<?php
include_once(APP_PATH."/collect/Lib/ORG/Zqnews.class.php");
if (!function_exists("createdir")) {
    function createdir($filepath)
    {
        $nn = preg_split("/(?<!\:)\//", $filepath);
        $temppath = "";
        for ($i = 0; $i < count($nn); $i++) {
            $temppath .= (($i > 0) ? "/" : "") . $nn[$i];
            if (!is_dir($temppath)) {
                @mkdir($temppath, 0777);
            }
        }
    }
}


if (!function_exists("u")) {
    function u($text)
    {
        $text = iconv("GB2312", 'utf-8//IGNORE', $text);
        return $text;
    }
}

if (!function_exists("g")) {
    function g($text)
    {
        $text = iconv("UTF-8", "GB2312//IGNORE", $text);
        return $text;
    }
}



function strip_jscss($str)
{
    preg_match_all("/<script\b[^<>]*>.*<\/\s*script\s*\/?>/Uisx", $str, $nn);
    for ($i = 0; $i < count($nn[1]); $i++) {
        if (preg_match("/reload|AC_FL_RunContent/Uisx", $nn[0][$i])) {
            if (preg_match("/http\:\/\/([^<>]*.swf)/Uisx", $nn[0][$i], $mm)) {
                $str = str_replace($nn[0][$i], "[media=swf,500,375]{$mm[0]}[/media]", $str);
                continue;
            }
        }
        $str = str_replace($nn[0][$i], "", $str);
    }
    $str = preg_replace("/<SCRIPT\b[^<>]*>.*(<\/\s*script\s*\/?>|$)/Uisx", "", $str);
    $str = preg_replace("/<\/?br\s*\/?>|&lt;\/br\s*\/?&gt;/Uisx", "\r\n", $str);
    $str = preg_replace("/<style\b[^<>]*>.*<\/\s*style\s*\/?>/Uisx", "", $str);
    $str = preg_replace("/<img[^<>]*src=\"[^<>]*\"[^<>]*file=\"([^<>]*)\"[^<>]*>/Uisx", "<img src=\"\\1\">", $str);
    $str = preg_replace("/(?<![=\"\'\]\[])(http\:\/\/[^<>]*\.(jpg|gif|png))/Uisx", "<img src=\"\\1\">", $str);
    $str = preg_replace("/([0-9]{4}\-[0-9]{1,2}\-[0-9]{1,2}|(半|[0-9])(小时|天)前)[^<>]*下载附件[^<>]*KB\)/", "", $str);
    return $str;
}

function my_array_max($arr)
{
    if (!empty($arr)) {
        foreach ($arr as $key => $value) {
            if (!isset($max) || ($max < $value)) {
                $max = $value;
                $max_key = $key;
            }
        }
    } else {
        return 0;
    }
    return $max_key;
}

if (!function_exists("unicode_encode1")) {
    function unicode_encode1($name)
    {
        $name = iconv('GB2312', 'UCS-2', $name);
        $len = strlen($name);
        $str = '';
        for ($i = 0; $i < $len - 1; $i = $i + 2) {
            $c = $name[$i];
            $c2 = $name[$i + 1];
            if (ord($c) > 0) {
                $str .= '\u' . base_convert(ord($c), 10, 16) . base_convert(ord($c2), 10, 16);
            } else {
                $str .= $c2;
            }
        }
        return $str;
    }


    function cn2utf8($str)
    {
        if (!is_utf8($str)) {
            $str = iconv("GB2312", "UTF-8//IGNORE", $str);

        }
        return $str;
    }


    function utf82cn($name)
    {
        $tostr = "";
        if (is_utf8($name)) {
            for ($i = 0; $i < strlen($name); $i++) {
                $curbin = ord(substr($name, $i, 1));
                if ($curbin < 0x80) {
                    $tostr .= substr($name, $i, 1);
                } elseif ($curbin < bindec("11000000")) {
                    $str = substr($name, $i, 1);
                    $tostr .= "&#" . ord($str) . ";";
                } elseif ($curbin < bindec("11100000")) {
                    $str = substr($name, $i, 2);
                    $tostr .= "&#" . GetUnicodeChar($str) . ";";
                    $i += 1;
                } elseif ($curbin < bindec("11110000")) {
                    $str = substr($name, $i, 3);
                    $gstr = iconv("UTF-8", "GB2312//IGNORE", $str);
                    //$gstr= iconv("UTF-8","GBK",$str);
                    if (!$gstr) {
                        $tostr .= "&#" . GetUnicodeChar($str) . ";";
                    } else {
                        $tostr .= $gstr;
                    }

                    $i += 2;
                } elseif ($curbin < bindec("11111000")) {
                    $str = substr($name, $i, 4);
                    $tostr .= "&#" . GetUnicodeChar($str) . ";";

                    $i += 3;
                } elseif ($curbin < bindec("11111100")) {
                    $str = substr($name, $i, 5);
                    $tostr .= "&#" . GetUnicodeChar($str) . ";";

                    $i += 4;
                } else {
                    $str = substr($name, $i, 6);
                    $tostr .= "&#" . GetUnicodeChar($str) . ";";

                    $i += 5;
                }
            }
            return $tostr;
        } else {
            return $name;
        }
    }

    function GetUnicodeChar($str)
    {
        $temp = "";
        for ($i = 0; $i < strlen($str); $i++) {
            $x = decbin(ord(substr($str, $i, 1)));
            if ($i == 0) {
                $s = strlen($str) + 1;
                $temp .= substr($x, $s, 8 - $s);
            } else {
                $temp .= substr($x, 2, 6);
            }
        }
        return bindec($temp);
    }

    function is_utf8($str)
    {
        if (preg_match("/\\\u[0-9a-z]{4}/i", $str)) {
            return true;
        }
        $c = 0;
        $b = 0;
        $bits = 0;
        $len = strlen($str);
        for ($i = 0; $i < $len; $i++) {
            $c = ord($str[$i]);
            if ($c > 128) {
                if (($c >= 254)) return false;
                elseif ($c >= 252) $bits = 6;
                elseif ($c >= 248) $bits = 5;
                elseif ($c >= 240) $bits = 4;
                elseif ($c >= 224) $bits = 3;
                elseif ($c >= 192) $bits = 2;
                else return false;
                if (($i + $bits) > $len) return false;
                while ($bits > 1) {
                    $i++;
                    $b = ord($str[$i]);
                    if ($b < 128 || $b > 191) return false;
                    $bits--;
                }
            }
        }
        return true;
    }


    function quanurl($subUrl, $wurl, $baseurl = "")
    {
        $subUrl=str_replace("\\","/",$subUrl);
        if (is_array($subUrl)) return;
        $hh=parse_url($wurl);
        if(preg_match("/^\/\//",$subUrl)){
            $subUrl=$hh['scheme'].":".$subUrl;
        }
        if(preg_match("/^blob\:/",$subUrl)){
            return $subUrl;
        }
        $wurl=urldecodeUrl($wurl);
        $baseurl=urldecodeUrl($baseurl);
        if(is_string($subUrl)) $subUrl=urldecode($subUrl);
        if (is_array($subUrl) || $subUrl == "") return "";
        preg_match("/(https?)\:\/\//Uisx",$wurl,$nn);
        $https=($nn[1]==null)?"http":$nn[1];
        $baseurl = preg_replace("/(https?\:\/\/[^\/]+)$/Uisx", "\\1/", $baseurl);
        if(!preg_match("/(https?\:\/\/[^\/]+)$/Uisx",$baseurl)){
            $baseurl="";
        }
        $subUrl = str_replace('\\', "/", trim($subUrl));
        $subUrl = str_replace('&amp;', "&", $subUrl);
        $subUrl = preg_replace("/^\.\?/", "?", $subUrl);
        $wurl = ($baseurl) ? $baseurl : $wurl;
        $wurl = preg_replace("/\?.*$/Uisx", "", $wurl);
        preg_match_all("/(https?\:\/\/([^\/]*?))(.*)$/Uimx", $wurl, $mm);
        $host = $mm[2][0];
        $subUrl=preg_replace("/^\/\//",$https."://",$subUrl);
        if (substr($subUrl, 0, 7) == "http://"||substr($subUrl, 0, 8) == "https://") {
            $newurl = $subUrl;
        } elseif (preg_match("/^\//", $subUrl)) {
            $newurl = "{$https}://" . $host . $subUrl;
        } elseif (preg_match("/^\.\.\//", $subUrl)) {
            $tmsuburl = $subUrl;
            $tempparentUrl = $wurl;
            preg_match_all("/(\.\.\/)/Uisx", $subUrl, $nn);
            for ($i = 0; $i < count($nn[1]); $i++) {
                $tmsuburl = preg_replace("/^\.\.\//", "", $tmsuburl);
                if(!preg_match("/https?\:\/\/[^<>\/]+\/?$/Uisx",$tempparentUrl)) {
                    $tempparentUrl = preg_replace("/(?!<\/)\/[^<>\/]*\/[^<>\/]*$/", "/", $tempparentUrl);
                }
            }
            $newurl = preg_replace("/\/$/", "", $tempparentUrl) . "/" . $tmsuburl;
        } elseif (preg_match("/^[^\.\/\?]/", $subUrl)) {
            preg_match("/^(.*)\//Uisx", $subUrl, $nna);
            preg_match("/https?\:\/\/.*\/(.*)\//Uisx", $wurl, $nnb);
            if ($nnb[1] == $nna[1]&&$nnb[1]!=null) {
                $newurl = $https."://" . $host . "/" . $subUrl;
            } elseif(!preg_match("/^http/i",$subUrl)) {
                $newurl = dirname2($wurl) . "/" . $subUrl;
            }elseif(preg_match("/^http/i",$subUrl)){
                $newurl = $subUrl;
            }
        } elseif (preg_match("/^\?/", $subUrl)) {
            $newurl = preg_replace("/\?.*$/U", "", $wurl) . $subUrl;
        } else {
            $newurl = preg_replace("/\/[^\/]*$/", "/", $wurl) . $subUrl;
        }
        $newurl = preg_replace("/\/\.\//", "/", $newurl);
        $newurl = preg_replace("/\/https?\:\//", "/", $newurl);
        $newurl = preg_replace("/[\r\n]/", "", $newurl);
        $newurl = preg_replace("/(https?\:)\/{1,}/", "\\1//", $newurl);
        return $newurl;
    }


    function dquanurl($nr, $wurl, $baseurl)
    {
        $nr = preg_replace("/(src|location|<link[^>]*href|<EMBED[^>]*VALUE|action|background|imgurl|<PARAM\s+NAME\=movie\s+VALUE|href)\s*=\s*(\"|\')?([^\"\'\>\s]+)(\\2|(?=\>)|\s)/Uisxe", "'\\1=\"'.quanurl('\\3','$wurl',\"$baseurl\").'\"'", $nr);
        $nr = preg_replace("/url\((\"|'|)?([^<>\s\"']+)\\1\)/Uisxe", '"url(".quanurl("\\2",$wurl).")"', $nr);
        //$nr=stripCSlashes($nr);
        return $nr;
    }

    function dirname2($wurl)
    {
        if (substr($wurl, -1, 1) == "/") {
            return substr($wurl, 0, -1);
        } else {
            return dirname($wurl);
        }
    }

    function host($str)
    {
        $str=urldecode($str);
        preg_match_all("/https?\:\/\/(?:[^<>\/]*?)([a-z0-9_]+?\.(?:com|gov|edu|org|mobi|la|us|hk|tw|net|cn|vn|cc|info|top|vip|me|xyz)(?:(?:\.net|\.cn|\.cc|\.tv|\.hk|\.tw|\.info|\.vn|\.top|\.vip)*(?=\:|\/|$)))/isx", $str, $nn);
        $host = $nn[1][0];
        $host = preg_replace("/^(?:[^<>]*\.)*([a-z0-9_]+\.(com|gov|edu|org|cn|mobi|la|hk|tw|us|cc|info|vn|top|vip|me|xyz))/Uisx", "\\1", $host);
        if($host==""&&preg_match("/https?\:\/\/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/",$str,$nn)){
            $host=$nn[1];
        }
        return $host;
    }

    function whost($str)
    {
        preg_match_all("/https?\:\/\/([^\/]+)/", $str, $nn);
        $whost = $nn[1][0];
        return $whost;
    }

    function clmh($str)
    {
        $str = preg_replace("/(\r|\n)+$/Uisx", "", trim($str));
        $str = preg_replace("/(\r|\n)+/m", "\\r\\n", trim($str));
        $str = preg_replace("/\"/m", "\\\"", trim($str));
        $str = preg_replace("/\&amp\;/m", "&", trim($str));
        return $str;
    }

    function droppagetablediv($nr, $nextpagere = "", $bug = 0)
    {
        if (!is_utf8($nextpagere)) $nextpagere = u($nextpagere);
        $re = ".*(?<![^\<\>a-z0-9_\s])(下一页|下页|上一页|上页" . $nextpagere . ").*";
        $nr = preg_replace("/<p[^<>]*>{$re}(<\/p>|(?:<\/(td|div)))/Uisx", "", $nr);
        $nr = preg_replace("/(<br>|<p[^<>]*>|\s)*<table[^<>]*>{$re}<\/table>/Uisx", "", $nr);
        $nr = preg_replace("/(<br>|<p[^<>]*>|\s)*&lt;table[^<>]*&gt;{$re}&lt;\/table&gt;/Uisx", "", $nr);
        $nr = preg_replace("/(<br>|<p[^<>]*>|\s)*<div[^<>]*>{$re}<\/div>/Uisx", "", $nr);
        $nr = preg_replace("/(<br>|<p[^<>]*>|\s)*&lt;div[^<>]*&gt;{$re}&lt;\/div&gt;/Uisx", "", $nr);
        $nr = preg_replace("/(\[?上一页|下一页|\[[0-9]+\](?:\[|\s\<)).*$/Uisx", "", $nr);
        $nr = preg_replace("/前一页|首页/Uisx", "", $nr);
        return $nr;
    }


    function mustzw($str)
    {
        preg_match_all("/([\x{4e00}-\x{9fa5}A-Za-z0-9_]+)/uisx", $str, $nn);
        return $nn[1][0];
    }

//通杀
    function tongx($str, $nr, $isint = 0)
    {


        $mm = preg_split("/,|\;/", $str);
        $arr = array();

        foreach ($mm as $one) {
            //for($i=0;$i<count($mm);$i++){
            if (trim($one) == "") continue;
            $isints = ($isint) ? "0-9\," : "^<>";
            switch ($isint) {
                case 1:
                    $isints = "0-9\,";
                    $u = "";
                    break;
                case 2:
                    $isints = "\x{4e00}-\x{9fa5}A-Za-z0-9_\'\\\"";
                    $u = "u";
                    break;
                default:
                    $isints = "^<>";
                    $u = "";
            }

            $re = "/" . chakai($one) . "(?:\:|：|：| | |<\/?(?:strong|b|a|font|td|span|th|em|li|span)[^<>]*>|\&nbsp\;|\s|　)+?([" . $isints . "]+?)/Uisx{$u}";
            if (preg_match_all($re, $nr, $nn)) {
                foreach ($nn[1] as $onn) {
                    if (trim($onn) != "") {
                        $arr[] = clwz($onn);
                    }
                }
            }


            $re = "/(?:<\/?(?:strong|b|a|font|td|span|th|em|li)[^<>]*>|\&nbsp\;|\s|　)([0-9\,]+?)(?:<\/?(?:strong|b|a|font|td|span|th|em|li)[^<>]*>|\&nbsp\;|\s)*" . chakai($one, 1) . "(?![\x{4e00}-\x{9fa5}A-Za-z0-9_]|\)|\,|，|。)/Uuisx";
            //echo $re."\r\n";

            if (preg_match_all($re, $nr, $nn)) {
                foreach ($nn[1] as $onn) {
                    if (trim($onn) != "") {
                        $arr[] = clwz($onn);
                    }
                }
            }


            $re = "/<META\s+name=\\\"" . chakai($one) . "\\\"\s+content=\\\"([^<>]*)\\\">/Uisx";
            if (preg_match_all($re, $nr, $nn)) {
                foreach ($nn[1] as $onn) {
                    if (trim($onn) != "") {
                        $arr[] = clwz($onn);
                    }
                }
            }
        }


        $return = "";
        foreach ($arr as $oarr) {
            if (strlen($oarr) > strlen($return)) {
                $return = $oarr;
            }
        }
        return $return;
    }

    function chakai($str, $nowei = 0)
    {
        //$str=addsla($str);
        if (!isutf8($str)) {
            $str = preg_replace("/([" . chr(0xb0) . "-" . chr(0xf7) . "][" . chr(0xa1) . "-" . chr(0xfe) . "])/", "\\1(?:\s| |\&nbsp\;|<(?:span|b|strong)[^<>]*>(?:<\/?(?:span|b|strong)>)?)*", $str); //GBK
        } else {
            $str = preg_replace("/([\x{4e00}-\x{9fa5}])/u", "\\1(?:\s| |\&nbsp\;|<(?:span|b|strong)[^<>]*>(?:<\/?(?:span|b|strong)>)?)*", $str); //utf8
        }
        if ($nowei) {
            $str = substr($str, 0, strlen("(?:\s| |\&nbsp\;|<(?:span|b|strong)[^<>]*>(?:<\/?(?:span|b|strong)>)?)*") * (-1));
        }
        return $str;
    }

    function addsla($yy)
    {
        $restr = str_replace("\\", "\\\\\\", $yy);
        $restr = str_replace(".*", "allall", $yy);
        $restr = str_replace(".", "\.", $restr);
        $restr = preg_replace("/\\\$/Uisx", "\\\\\\\\\\\\$", $restr);
        $restr = preg_replace("/\"/Uisx", "\\\"", $restr);
        $restr = preg_replace("/\-/Uisx", "\\-", $restr);
        $restr = preg_replace("/\:/Uisx", "\\:", $restr);
        $restr = preg_replace("/\?/Uisx", "\\?", $restr);
        $restr = preg_replace("/\//Uisx", "\\/", $restr);
        $restr = preg_replace("/\{/Uisx", "\\{", $restr);
        $restr = preg_replace("/\}/Uisx", "\\}", $restr);
        $restr = preg_replace("/\(/Uisx", "\\(", $restr);
        $restr = preg_replace("/\)/Uisx", "\\)", $restr);
        $restr = preg_replace("/\|/Uisx", "\\|", $restr);
        $restr = preg_replace("/\,/Uisx", "\\,", $restr);
        $restr = preg_replace("/\!/Uisx", "\\!", $restr);
        $restr = preg_replace("/\^/Uisx", "\\^", $restr);
        $restr = preg_replace("/\*/Uisx", ".*", $restr);
        $restr = preg_replace("/\#/Uisx", "\\#", $restr);
        $restr = preg_replace("/\]/Uisx", "\\]", $restr);
        $restr = preg_replace("/\[/Uisx", "\\[", $restr);
        $restr = preg_replace("/\+/Uisx", "\\+", $restr);
        $restr = preg_replace("/((\\s\+)?(\\n)?\\s)+/m", "\\\s+", $restr);
        $restr = preg_replace("/MMM$/Uisx", "", $restr);
        $restr = preg_replace("/\\\\s\+MMM\\\\s\+/", "[\s\\n]+", $restr);
        $restr = str_replace("allall", ".*", $restr);
        return $restr;
    }

    function clwz($str)
    {
        $str = preg_replace("/\'(.*)\'.*$/Uisx", "\\1", $str);
        $str = preg_replace("/'|\"|\\\\\"|null|【|】|：|\:/Uisx", "", $str);
        $str = preg_replace("/([0-9]+)[\x{4e00}-\x{9fa5}<]*$/Uuisx", "\\1", $str);
        return $str;
    }


    function cltitle($str)
    {
        $str = preg_replace("/\\\'/Uisx", "'", $str);
        $str = preg_replace("/\\\\\"/Uisx", '"', $str);
        if(preg_match("/^\"(.*)\"$/Uisx",$str,$nn)){
            $str=stripcslashes($nn[1]);
        }
        return $str;
    }

    function htmltotxt($str, $n = 0, $thisurl = "", $thisbaseurl = "", $lie_a = false,$keeptable=0)
    {
        global $rs;
        $str = trim($str);
        $str = preg_replace("/\"/", "\\\"", strip_tags2($str, "strong|b|p|img|br|td|table|tr|ul|li|span|hr"));
        preg_match_all("/<img(.*)(?<!width|height|\=|\.|width\s)>/Uisx", $str, $nn00);
        for ($i = 0; $i < count($nn00[1]); $i++) {
            $tmp = preg_replace("/\\\(?!\'|\")/", "/", $nn00[0][$i]);
            preg_match_all("/file\s*\=\s*\\\?\"([^<>]*)\\\??\"/Uisx", $tmp, $nnn3);
            $src = trim($nnn3[1][0]);
            if ($src == "") {
                preg_match_all("/original\s*\=\s*\\\?\"([^<>]*)\\\??\"/Uisx", $tmp, $nnn2);
                $src = trim($nnn2[1][0]);
            }
            if ($src == "") {
                preg_match_all("/(?:real_src|data-lazyload-src|data-original|crs|src[0-9]+)\s*\=\s*\\\?\"([^<>]*)\\\??\"/Uisx", $tmp, $nnn2);
                $src = trim($nnn2[1][0]);
            }
            if ($src == "") {
                preg_match_all("/src[0-9\s]*\=[\s\\\?\"\']*?([^<>\s\\\'\"]*?)/Uisx", $tmp, $nnn2);
                $src = trim($nnn2[1][0]);
            }
            if ($rs['loadimg'] == 1) {
                $str = str_replace($nn00[0][$i], "\r\n[img]http://collect.longsunhd.com/source/plugin/yzs1013_pldr/getimg.php?url=" . surlencode(quanurl(trim($src), $thisurl, $thisbaseurl)) . "[/img]\r\n<p>\r\n", $str);
            } else {
                $str = str_replace($nn00[0][$i], "\r\n&nbsp;\r\n[img]" . quanurl(trim($src), $thisurl, $thisbaseurl) . "[/img]\r\n<p>\r\n&nbsp;\r\n", $str);
            }
        }
        $str = preg_replace("/\&ldquo\;/Uisx", "\"", $str);
        $str = preg_replace("/\&rdquo\;/Uisx", "\"", $str);
        $str = preg_replace("/<(\/?)\s*(br|p)[^<>]*>/isx", "\r\n", $str);
        $str = preg_replace("/(\r\s*\n)+/m", "\r\n", $str);
        if(!$keeptable) {
            $str = preg_replace("/<(\/?)(td|table|tr|li|ul)\b([^<>]*)>/Uisx", "", $str);
        }
        $str = preg_replace("/\[img\][^<>\[\]]*Array\[\/img\]/Usx", "", $str);
        $str = preg_replace("/^\s*　　\s*(http\:\/\/[^<>]*\.jpg)\s*$/Uixm", "\r\n　　[img]\\1[/img]\r\n", $str);
        $str = preg_replace("/([\r\n](\s|　)*[\r\n])+/im", "\r\n", $str);
        //$str = preg_replace("/^(　)*(.*)$/ime", '"\r\n　　".trim("\\2").""', $str);
        $str = preg_replace("/\&[a-z]+\;/isx", "", $str);
        $str = preg_replace("/(\]|。|；|？)(　|\s)+/Uisx", "\\1\r\n　　", $str);
        $str = preg_replace("/" . g("(\]|。|；|？)(　|\s)+") . "/Uisx", "\\1\r\n　　", $str);
        $str = trim(preg_replace("/^(　|\s|\&nbsp\;)*/im", "\r\n　　", $str));
        $str = str_replace('\"', '"', $str);
        return trim($str);
    }

    function getre($host, $fieldname = "nr", $gather_type = 1)
    {
        //$t = new t("localhost","root","gxwmw159456","longzs");
        $t = new t("localhost", "root", "159456", "longzs");
        $rs = $t->sqlone("select * from longzs_re where host='" . trim($host) . "'  ORDER BY updatetime DESC");
        return $rs;
    }

    function qz($re, $nr = "")
    {
        preg_match_all("/" . trim($re) . "/Uisx", $nr, $nn);
        return $nn[1][0];
    }


    function redo($url, &$secexe = 0, $soucere = "", $mbre = "", $starti = 0, $endi = 0, $sameurlre = "\/([^<>\/]*)\/[^<>\/]*$")
    {
        global $news2;
        static $leiji, $setin;

        if($url!=$GLOBALS['oldredourl']){
            $GLOBALS['oldredourl']=$url;
        }else{
            bug("redo",array("url"=>$url));
            return "";
        }

        $leiji = ($leiji == "") ? 0 : $leiji;
        $str = "";
        $oldnr = "";
        $oldurl = "";
        $url2 = "";
        jsstart();
        preg_match("/$sameurlre/Uisx", $url, $nn);
        if ($setin != $nn[1][0] && $setin != "") return "";
        $setin = $nn[1][0];
        for ($i = $starti; $i <= $endi; $i++) {
            $url2 = $url;
            if ($soucere != "" && $mbre != "") {
                $url2 = preg_replace("/" . $soucere . "/Uisx", preg_replace("/%1/Uisx", $i, $mbre), $url2);
            }
            //echo "\r\n\r\n\r\npage:{$i}------------$url------$soucere------$mbre-------".$url2;
            if ($url2 == $oldurl) {
                break;
            } else {
                if ($news2->bug == 2) echo "\r\n\r\n\r\n--page:{$i}------------$url-------------------" . $url2;
                $oldurl = $url2;
            }
            if ($news2->bug == 2) echo "\r\n" . ceil(js()) . "\r\n";
            if (ceil(js()) > 30 || $leiji > 40) return $str;
            $leiji++;
            $news2 = new Zqnews($url2);
            $secexe = $news2->secexe = 1;
            $nr = $news2->getnr();
            $GLOBALS[title] = cltitle($news2->getbt());
            $str .= "\r\n" . $nr;
            //$nr = (!is_utf8($nr)) ? u($nr) : $nr;
            if (!strcmp($nr, $oldnr)) {
                break;
            } else {
                $oldnr = $nr;
            }
        }
        $str = preg_replace("/\[align=center\]\[\/align\]/", "", $str);
        return $str;

    }


    function strip_tags2($str, $s)
    {
        $str = preg_replace("/(desc|alt)=\"(.*)\"/Uisxe", '"\\1=\"".strip_tags3("\\2")."\""', $str);
        $str = preg_replace("/<(?!\/|" . $s . "|script|b|strong).*(?<!width|height|\=|\.|width\s)>/Uisx", "", $str);
        $str = preg_replace("/<\/(?!" . $s . "|script|b|strong).*(?<!width|height|\=|\.|width\s)>/Uisx", "", $str);
        return $str;

    }

    function strip_tags3($str)
    {
        $str = preg_replace("/\&lt\;.*\&gt\;/Uisx", "", $str);
        return $str;

    }


    function addsla2($str, $args = array())
    {
        $nn = preg_split("/@@/", $str);
        $n = 0;

        do {
            preg_match_all("/.*?(\(\.\*\)|\(\.\+\)|\(\[\^\<\>\]\*\)|\\\\\\/|\(\[[<>\+\\\-_a-z\%\/0-9\^\$]+\]\*\)|\:y\b|\:nn[0-9]+?|\.\*|\[[<>\+\\\-_a-z\%\/0-9\^\$]+\]|\[0\-9\]|\{标题\}|\{内容\}|\{变量[0-9]+\}|\\\"|\\\(|\\\)|\\\'|\\\s+|\\\r|\\\n|\+|\*|\\\$|\\\^)/isx", trim($nn[0]), $mm);
            $replace_times = 1;
            $nn[0] = str_replace($mm[1][0], "&&" . $n . "&&", $nn[0], $replace_times);
            $arr[$n] = $mm[1][0];
            $n++;
        } while (count($mm[1]) > 0 && $n < 5);
        $nn[0] = addsla($nn[0]);
        $nn[0] = preg_replace("/&&([0-9]+)&&/Uisxe", '$arr["\\1"]', $nn[0]);
        $nn[0] = str_replace("\\", "\\\\", $nn[0]);
        if (count($nn) == 1) {
            return $nn[0];
        } else {
            return $nn[0] . "@@" . $nn[1];
        }
    }

    function jcre($txt, $args = array())
    {
        extract($args);
        if(substr(trim($txt),0,1)=="."||substr(trim($txt),0,1)=="#"||preg_match("/^(div\b|a\b|span\b|p\b|li\b|em\b|h[0-9]+|td\b|tr\b|strong\b)/Uisx",trim($txt))){
            return $txt;
        }
        preg_match_all("/^(.*)$/Uimx", $txt, $nn);
        for ($i = 0; $i < count($nn[1]); $i++) {
            $dd = preg_split("/@@/", $nn[1][$i]);
            $ynn[1][$i] = $dd[0];
            preg_match("/@'(.*)'/Uisx", $dd[0], $nn22);
            $dd[0] = str_replace($nn22[0], "baoliu", $dd[0]);
            $dd[0] = preg_replace("/(\.|。|" . g("。") . "|\*){3,}/", "(.*)", $dd[0]);
            $dd[0] = preg_replace("/(\<|\>){3,}/", "([^<>]*)", $dd[0]);
            $dd[0] = preg_replace("/(?<![0-9])0{3,}/", "([^<>]*)", $dd[0]);
            if (preg_match("/(?<!\\\)\"|\s|(?<!\\\)\//Uis", trim($dd[0]))) {
                $txt = str_replace(trim($ynn[1][$i]), addsla2(trim($dd[0])), $txt);
            }
            $txt = str_replace("baoliu", $nn22[0], $txt);
        }
        return $txt;
    }

    function addsla0($str)
    {
        $str = str_replace('\\', '\\\\\\\\', $str);
        return $str;
    }


    function striponexg($str)
    {
        $str = str_replace('\\', "&&&&", $str);
        $str = preg_replace("/\\\/", "", $str);
        $str = preg_replace('/&&&&/', "\\", $str);
        return $str;

    }

    function istextarea($str)
    {
        if (preg_match("/\。|，|“|：|\&nbsp\;|<img/Uisx", $str) || strlen($str) > 100) {
            return true;
        }
        return false;
    }

    function curl_file_get_contents($durl)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $durl);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_setopt($ch, CURLOPT_USERAGENT, _USERAGENT_);
        curl_setopt($ch, CURLOPT_REFERER, _REFERER_);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        $r = curl_exec($ch);
        curl_close($ch);

        if (preg_match("/Location:\s*([^\r\n]+)/isx", $r, $nn)) {
            $durl = trim($nn[1]);
            $r = curl_file_get_contents($durl);
        } else {
            preg_match_all("/(^.*)\r\n\r\n(.+?)$/Uis", $r, $nn);
            $r = chunk($nn[2][0]);
        }
        return $r;
    }


    function curl_file_get_contents2($urlArray)
    {
        if (empty($urlArray)) return false;
        $isStr = false;
        if (is_string($urlArray)) {
            $urlArray = array($urlArray);
            $isStr = true;
        }
        $mh = curl_multi_init(); //curl_multi_init --  Returns a new cURL multi handle
        $curlArray = array();
        foreach ($urlArray as $i => $url) {
            $curlArray[$i] = curl_init($url);
            curl_setopt($curlArray[$i], CURLOPT_RETURNTRANSFER, true); //设置为true表示返回抓取的内容，而不是直接输出到浏览器上。TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly
            curl_setopt($curlArray[$i], CURLOPT_AUTOREFERER, true); //自动设置referer。TRUE to automatically set the Referer: field in requests where it follows a Location: redirect.
            curl_setopt($curlArray[$i], CURLOPT_FOLLOWLOCATION, true); //跟踪url的跳转，比如301, 302等
            curl_setopt($curlArray[$i], CURLOPT_MAXREDIRS, 2); //跟踪最大的跳转次数
            curl_setopt($curlArray[$i], CURLOPT_HEADER, 0); //TRUE to include the header in the output.
            curl_setopt($curlArray[$i], CURLOPT_ENCODING, ""); //接受的编码类型,The contents of the "Accept-Encoding: " header. This enables decoding of the response. Supported encodings are "identity", "deflate", and "gzip". If an empty string, "", is set, a header containing all supported encoding types is sent.
            curl_setopt($curlArray[$i], CURLOPT_CONNECTTIMEOUT, 5); //连接超时时间
            curl_multi_add_handle($mh, $curlArray[$i]); //curl_multi_add_handle --  Add a normal cURL handle to a cURL multi handle
        }

        $running = NULL;
        $count = 0;
        do {
            //10秒钟没退出，就超时退出
            if ($count++ > 50) break;
            usleep(50000);
            curl_multi_exec($mh, $running); //curl_multi_exec --  Run the sub-connections of the current cURL handle
        } while ($running > 0);

        $content = array();
        foreach ($urlArray as $i => $url) {
            $content[$url] = curl_multi_getcontent($curlArray[$i]); //curl_multi_getcontent --  Return the content of a cURL handle if CURLOPT_RETURNTRANSFER is set
        }

        //curl_multi_remove_handle --  Remove a multi handle from a set of cURL handles
        foreach ($urlArray as $i => $url) {
            curl_multi_remove_handle($mh, $curlArray[$i]);
        }

        //curl_multi_close --  Close a set of cURL handles
        curl_multi_close($mh);
        //如果参数$urlArray是字符串，则将返回值也转换为字符串
        if ($isStr) $content = implode('', $content);
        return $content;
    }


    function curl_file_get_contents3($array, $timeout = 10)
    {
        $res = array();
        if (is_string($array)) $array = array($array);
        $mh = curl_multi_init(); //创建多个curl语柄
        $startime = getmicrotime();
        $ch = curl_init();
        if(!empty($array)) {
            foreach ($array as $k => $url) {
                $conn[$k] = curl_init($url);
                curl_setopt($conn[$k], CURLOPT_TIMEOUT, $timeout); //设置超时时间
                $user_agent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
                curl_setopt($conn[$k], CURLOPT_USERAGENT, $user_agent);
                curl_setopt($conn[$k], CURLOPT_MAXREDIRS, 7); //HTTp定向级别
                curl_setopt($conn[$k], CURLOPT_HEADER, 0); //这里不要header，加块效率
                curl_setopt($conn[$k], CURLOPT_FOLLOWLOCATION, 1); // 302 redirect
                curl_setopt($conn[$k], CURLOPT_RETURNTRANSFER, 1);
                @curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
                @curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
                @curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
                curl_multi_add_handle($mh, $conn[$k]);
            }
        }

        //防止死循环耗死cpu 这段是根据网上的写法
        //防止死循环耗死cpu这段是根据网上的写法 返回头信息 释放资源 关闭句柄
//        do {
//            $mrc = curl_multi_exec($mh,$active);//当无数据，active=true
//        } while ($mrc == CURLM_CALL_MULTI_PERFORM);//当正在接受数据时
//        while ($active and $mrc == CURLM_OK) {//当无数据时或请求暂停时，active=true
//            if (curl_multi_select($mh) != -1) {
//                do {
//                    $mrc = curl_multi_exec($mh, $active);
//                } while ($mrc == CURLM_CALL_MULTI_PERFORM);
//            }
//        }

        foreach ($array as $k => $url) {
            curl_error($conn[$k]);
            $res[$k] = curl_multi_getcontent($conn[$k]); //获得返回信息
            $header[$k] = curl_getinfo($conn[$k]); //返回头信息
            curl_close($conn[$k]); //关闭语柄
            curl_multi_remove_handle($mh, $conn[$k]); //释放资源
        }

        curl_multi_close($mh);
        $endtime = getmicrotime();
        $diff_time = $endtime - $startime;
        $return = array('diff_time' => $diff_time,
            'return' => $res,
            'header' => $header
        );
        return $return['return'][0];
    }


    function getmicrotime()
    {
        list($usec, $sec) = explode(" ", microtime());
        return ((float)$usec + (float)$sec);
    }

    function swf_replace($nr, $thisurl, &$swfstr, $host = "")
    {
        $arr = array();
        $nr = preg_replace("/<div\s+class=\"cornerlayger\">(.*)<\/div>/Uisx", "", trim($nr));
        $nr = preg_replace("/<p\s+class=\"imgtitle\">(.*)<\/p>/Uisx", "", $nr);
        $nr = preg_replace("/<div\s+class=\"cornerlayger\">(.*)<\/div>/Uisx", "", $nr);
        $nr = preg_replace("/点击图片进入下一页|点击图片进下页/Uisx", "", $nr);
        if ($host == "sina.com.cn") {
            if (preg_match_all("/<\!\-\-\s*flash\s+player\s+begin\s+\-\->.*<\!\-\-\s+flash\s+player\s+end\s+\-\-\>/Uisx", $nr, $nn)) {
                $swfstr = $nn[0][0];
                return $nr;
            }
            //$fn=fopen("d:/1.txt","w");fwrite($fn,$thisurl."\r\n".$nr);fclose($fn);
            if (preg_match_all("/<div[^<>]*id=\"artibody\"[^<>]*>.*<\!\-\-\spublish_helper_end\s\-\->.*<\/div>/Uisx", $nr, $nn)) {
                $swfstr = $nn[0][0];
                return $nr;
            }

            $temp = swfhost($nr, $thisurl, $swfstr, "sina.com.cn");
            if ($temp != "") $swfstr .= "[flv,500,400]" . $temp . "[/flv]\r\n";
        }


//echo $swfstr;exit;
        preg_match_all("/(<object[^<>]*>(.*<\/object>)?)/Uisx", $nr, $nn);
        for ($i = 0; $i < count($nn[1]); $i++) {
            if (preg_match("/\/ad\//i", $nn[1][$i])) continue;
            if (preg_match("/name=\"filename\"\s+value=\"([^<>]*\.(swf|flv|rm|rmvb|mov|avi|wmv|hlv)[^<>]*)\"/Uisx", $nn[1][$i], $ss)) {
                $mm = $ss;
            }

            if ($mm == "" && preg_match("/value=\"[^<>\s\"\']*(http:\/\/[^<>\s\"\']*\.(flv|rm|rmvb|mov|avi|wmv|hlv))[^<>]*\"/Uisx", $nn[1][$i], $ss)) {
                $mm = $ss;
            }

            if ($mm == "" && preg_match("/value=\"[^<>\s\"\']*(http:\/\/[^<>\s\"\']*\.(swf))[^<>]*\"/Uisx", $nn[1][$i], $ss)) {
                $mm = $ss;
            }

            if (in_array($mm[1], $arr)) continue;
            $arr[] = $mm[1];
            preg_match("/WIDTH\:\s*([0-9]+)px/Uisx", $nn[1][$i], $mm2);
            $width = $mm2[1];
            preg_match("/height\:\s*([0-9]+)px/Uisx", $nn[1][$i], $mm2);
            $height = $mm2[1];
            if ($width == "") {
                preg_match("/width=\"([0-9]+)\"/Uisx", $nn[1][$i], $mm2);
                $width = $mm2[1];
            }
            if ($height == "") {
                preg_match("/height=\"([0-9]+)\"/Uisx", $nn[1][$i], $mm2);
                $height = $mm2[1];
            }
            if (preg_match("/flashvars=\"(.*)\"/Uisx", $nn[1][$i], $mm3)) {
                $vars = (preg_match("/\?/", $mm[1]) ? "&" : "?") . $mm3[1];
            }
            if (!preg_match("/flv|swf|avi|rm|mp[0-9]|mov|wmv/i", $mm[1]) || (!preg_match("/\=/i", $mm[1] . $vars) && !preg_match("/[0-9]{3,}(?\.\/)/i", $mm[1] . $vars)) || preg_match("/\'|\"/i", $mm[1] . $vars)) continue;
            $flvurl = quanurl($mm[1], $thisurl) . $vars;
            if ($width < 1000 && $height > 300 && trim($flvurl) != "") {
                if (preg_match("/swf|flv/Uisx", "$mm[2]")) {
                    $swfstr .= "[flash={$width},{$height}]" . $flvurl . "[/flash]\r\n";
                    //$nr=str_replace($nn[0][$i],"[flash=x,{$width},{$height}]".quanurl($mm[1],$thisurl)."[/flash]\r\n",$nr);
                } elseif (preg_match("/avi|mpg|mpeg|rm|wmv|mov|mp[0-9]+/Uisx", "$mm[2]")) {
                    $swfstr .= "[media={$width},{$height}]" . $flvurl . "[/media]\r\n";
                    //$nr=str_replace($nn[0][$i],"[media=x,{$width},{$height}]".quanurl($mm[1],$thisurl)."[/media]\r\n",$nr);
                }
            }

        }


        if (preg_match_all("/vid=([^<>]*)(\&|\"|$|\>)/isx", $nr, $mm)) {
            $vid = $mm[1][0];
            if ($width == "") {
                preg_match("/width=\"([0-9]+)\"/Uisx", $nn[1][$i], $mm2);
                $width = $mm2[1];
            }
            if ($height == "") {
                preg_match("/height=\"([0-9]+)\"/Uisx", $nn[1][$i], $mm2);
                $height = $mm2[1];
            }

            if ($host == "ku6.com") {
                $mm[1] = "http://player.ku6.com/refer/{$vid}/v.swf";
                $mm[2] = "http://player.ku6.com/refer/{$vid}/v.swf";
            }

            $arr[] = $mm[1];
            //echo $nn[2];exit;
            if ($width <= 1000 && $height > 200 && trim($mm[2]) != "") {
                if (preg_match("/swf|flv/Uisx", "$mm[2]", $mmz)) {
                    $swfstr .= "[flash={$width},{$height}]" . quanurl($mm[1], $thisurl) . "[/flash]\r\n";
                } elseif (preg_match("/avi|mpg|mpeg|rm|wmv|mov|mp[0-9]+/Uisx", "$mm[2]")) {
                    $swfstr .= "[media={$width},{$height}]" . quanurl($mm[1], $thisurl) . "[/media]\r\n";
                }
            }
        }

        preg_match_all("/(<embed[^<>]*>(.*<\/embed>)?)/Uisx", $nr, $nn);
        for ($i = 0; $i < count($nn[1]); $i++) {
            if (preg_match("/\/ad\//i", $nn[1][$i]) || trim($nn[1][$i]) == "") continue;
            if (preg_match("/(?:file|src)=([^<>]*\.(swf|flv|rm|rmvb|mov|avi|wmv|hlv|mp[0-9]+)[^<>]*)\"/Uisx", $nn[1][$i], $mm)) {
                $mm[1] = urldecode(preg_replace("/\"/", "", $mm[1]));
                $mm[1] = preg_replace("/autostart=false/", "autostart=true", $mm[1]);
                $mm[1] = preg_replace("/&amp;/", "&", $mm[1]);
                if (in_array($mm[1], $arr)) continue;
                $arr[] = $mm[1];
                preg_match("/WIDTH=\"?\s*([0-9]+)/isx", $nn[1][$i], $mm2);
                $width = $mm2[1];
                preg_match("/height=\"?\s*([0-9]+)/isx", $nn[1][$i], $mm2);
                $height = $mm2[1];
                if (preg_match("/flashvars=\"(.*)\"/Uisx", $nn[1][$i], $mm3)) {
                    $vars = (preg_match("/\?/", $mm[1]) ? "&" : "?") . $mm3[1];
                }
                if (!preg_match("/flv|swf|avi|rm|mp[0-9]|mov|wmv/i", $mm[1]) || preg_match("/\'|\"/i", $mm[1] . $vars)) continue;
                if (preg_match("/swf|flv/Uisx", "$mm[2]")) {
                    $swfstr .= "[flash={$width},{$height}]" . quanurl($mm[1], $thisurl) . $vars . "[/flash]\r\n";
                    //$nr=str_replace($nn[0][$i],"[flash=x,{$width},{$height}]".quanurl($mm[1],$thisurl)."[/flash]\r\n",$nr);
                } elseif (preg_match("/avi|mpg|mpeg|rm|wmv|mov|mp[0-9]+/Uisx", "$mm[2]")) {
                    $swfstr .= "[media={$width},{$height}]" . quanurl($mm[1], $thisurl) . $vars . "[/media]\r\n";
                    //$nr=str_replace($nn[0][$i],"[media=x,{$width},{$height}]".quanurl($mm[1],$thisurl)."[/media]\r\n",$nr);
                }
            }

        }

        preg_match_all("/\&lt\;object.*param\s+name=\&quot\;movie\&quot\;\s+value=\&quot\;([^<>]+)\&quot\;/Uisx", $nr, $nn);
        for ($i = 0; $i < count($nn[1]); $i++) {
            if (preg_match("/\/ad\//i", $nn[1][$i])) continue;
            preg_match("/WIDTH=(?:\"|\&quot\;)?\s*([0-9]+)/isx", $nn[$i][0], $mm2);
            $width = $mm2[1];
            preg_match("/height=(?:\"|\&quot\;)?\s*([0-9]+)/isx", $nn[$i][0], $mm2);
            $height = $mm2[1];
            if (!preg_match("/flv|swf|avi|rm|mp[0-9]|mov|wmv/i", $nn[1][$i]) || (!preg_match("/\=/i", $nn[1][$i] . $vars) && !preg_match("/[0-9]{3,}(?\.\/)/i", $nn[1][$i] . $vars)) || preg_match("/\'|\"/i", $nn[1][$i] . $vars)) continue;
            if ($width <= 1000 && $height > 200) {
                if (preg_match("/swf|flv/Uisx", "$nn[1][$i]", $oo)) {
                    $swfstr .= "[flash={$width},{$height}]" . quanurl($nn[1][$i], $thisurl) . "[/flash]\r\n";
                } elseif (preg_match("/avi|mpg|mpeg|rm|wmv|mov|mp[0-9]+/Uisx", "$mm[2]")) {
                    $swfstr .= "[media={$width},{$height}]" . quanurl($nn[1][$i], $thisurl) . "[/media]\r\n";
                }
            }
        }

        preg_match_all("/\,videoSrc\:\s+\'(.*)\'/Uisx", $nr, $nn);
        for ($i = 0; $i < count($nn[1]); $i++) {
            preg_match("/WIDTH=(?:\"|\&quot\;)?\s*([0-9]+)/isx", $nn[$i][0], $mm2);
            $width = $mm2[1];
            preg_match("/height=(?:\"|\&quot\;)?\s*([0-9]+)/isx", $nn[$i][0], $mm2);
            $height = $mm2[1];
            if (preg_match("/swf|flv/Uisx", "$nn[1][$i]", $oo)) {
                $swfstr .= "[flash=580,280]" . quanurl($nn[1][$i], $thisurl) . "[/flash]\r\n";
            } elseif (preg_match("/avi|mpg|mpeg|rm|wmv|mov|mp[0-9]+/Uisx", "$mm[2]")) {
                $swfstr .= "[media=580,280]" . quanurl($nn[1][$i], $thisurl) . "[/media]\r\n";
            }
        }

        preg_match_all("/var\s*ad\s*=\s*'([^<>]*)';\s*var\s*w\s*=\s*'([0-9]*)';\s*var\s*h\s*=\s*'([0-9]*)';/Uisx", $nr, $nn);
        for ($i = 0; $i < count($nn[1]); $i++) {
            if (preg_match("/swf|flv/Uisx", "$nn[1][$i]", $oo)) {
                $swfstr .= "[flash={$nn[2][$i]},{$nn[3][$i]}]" . quanurl($nn[1][$i], $thisurl) . "[/flash]\r\n";
            } elseif (preg_match("/avi|mpg|mpeg|rm|wmv|mov|mp[0-9]+/Uisx", "$mm[2]")) {
                $swfstr .= "[media={$nn[2][$i]},{$nn[3][$i]}]" . quanurl($nn[1][$i], $thisurl) . "[/media]\r\n";
            }
        }


        preg_match_all("/<script[^<>]*>(.*)<\/script>/Uisx", $nr, $nn);
        for ($i = 0; $i < count($nn[1]); $i++) {
            if (preg_match("/\/ad\//i", $nn[1][$i])) continue;
            if (preg_match("/\"file\"\s*\,\s*\"([^<>]*\.(swf|flv|rm|rmvb|mov|avi|wmv|hlv))\"/Uisx", $nn[1][$i], $ss)) {
                $mm = $ss;
            }
            if (preg_match("/file\s*\:\s*\"([^<>]*\.(swf|flv|rm|rmvb|mov|avi|wmv|hlv))\"/Uisx", $nn[1][$i], $ss)) {
                $mm = $ss;
            }
            if (preg_match("/data\s*=\s*([^<>]*\.(swf|flv|rm|rmvb|mov|avi|wmv|hlv))/Uisx", $nn[1][$i], $ss)) {
                $mm = $ss;
            }
            if (preg_match("/'src'\s*\,\s*'([^<>]*)'/Uisx", "$nn[1][$i]", $ss)) {
                $mm = $ss;
                $flash = 1;
            }

            if (in_array($mm[1], $arr)) continue;
            $arr[] = $mm[1];
            if (preg_match("/width\"?\s*(?:,|\:|\=)\s*\"?\s*([0-9]+)/isx", $nn[1][$i], $mm2)) $width = $mm2[1];
            if (preg_match("/height\"?\s*(?:,|\:|\=)\s*\"?\s*([0-9]+)/isx", $nn[1][$i], $mm2)) $height = $mm2[1];
            if (preg_match("/width=\"([0-9]+)\"/Uisx", $nn[1][$i], $mm2)) $width = $mm2[1];
            if (preg_match("/height=\"([0-9]+)\"/Uisx", $nn[1][$i], $mm2)) $height = $mm2[1];
            if (preg_match("/'width'\,'([0-9]+)'\,'height'\,'([0-9]+)'/Uisx", $nn[1][$i], $mm2)) {
                $width = $mm2[1];
                $height = $mm2[2];
            }
            if (preg_match("/'width'\,'([0-9]+)'\,'height'\,'([0-9]+)'/Uisx", $nn[1][$i], $mm2)) {
                $width = $mm2[1];
                $height = $mm2[2];
            }


            $flvurl = quanurl($mm[1], $thisurl);
            if ($width <= 1000 && $height > 200 && $flvurl != "" && !preg_match("/\"/", $flvurl)) {
                if (preg_match("/swf|flv/Uisx", "$mm[2]") || $flash) {
                    $swfstr .= "[flash={$width},{$height}]" . $flvurl . "[/flash]\r\n";
                    //$nr=str_replace($nn[0][$i],"[flash=x,{$width},{$height}]".quanurl($mm[1],$thisurl)."[/flash]\r\n",$nr);
                } elseif (preg_match("/avi|mpg|mpeg|rm|wmv|mov|mp[0-9]+/Uisx", "$mm[2]")) {
                    $swfstr .= "[media={$width},{$height}]" . $flvurl . "[/media]\r\n";
                    //$nr=str_replace($nn[0][$i],"[media=x,{$width},{$height}]".quanurl($mm[1],$thisurl)."[/media]\r\n",$nr);
                }
            }
        }

        if ($vid == "" && preg_match("/\/v\/[0-9]\/[a-z]\/([^<>]+)\.html/Uisx", $thisurl, $vv)) {
            $vid = $vv[1];
            if ($host == "qq.com") {
                $nn[1][0] = "http://static.video.qq.com/TPout.swf?vid={$vid}&auto=1";
                if (preg_match("/swf|flv/Uisx", $nn[1][$i], $oo)) {
                    $swfstr .= "[flash=580,280]" . quanurl($nn[1][0], $thisurl) . "[/flash]\r\n";
                } elseif (preg_match("/avi|mpg|mpeg|rm|wmv|mov|mp[0-9]+/Uisx", "$mm[2]")) {
                    $swfstr .= "[media=580,280]" . quanurl($nn[1][0], $thisurl) . "[/media]\r\n";
                }
            }
        }
        if ($vid == "" && preg_match("/\?vid=([^\&<>]+)/isx", $thisurl, $vv)) {
            $vid = $vv[1];
            if ($host == "qq.com") {
                $nn[1][0] = "http://static.video.qq.com/TPout.swf?vid={$vid}&auto=1";
                if (preg_match("/swf|flv/Uisx", $nn[1][$i], $oo)) {
                    $swfstr .= "[flash=580,280]" . quanurl($nn[1][0], $thisurl) . "[/flash]\r\n";
                } elseif (preg_match("/avi|mpg|mpeg|rm|wmv|mov|mp[0-9]+/Uisx", "$mm[2]")) {
                    $swfstr .= "[media=580,280]" . quanurl($nn[1][0], $thisurl) . "[/media]\r\n";
                }
            }
        }

        if (preg_match_all("/(mms\:\/\/.*\.wmv)/Uisx", $nr, $nn)) {
            $swfstr .= "[flash]" . $nn[1][0] . "[/flash]\r\n";
        }

        $swfstr = preg_replace("/vid\=\&/Uisx", "vid={$vid}&", $swfstr);
        $swfstr = preg_replace("/vid=\'\s*vid\s*\'/Uisx", "vid={$vid}", $swfstr);


        return $nr;
    }

    function changeloadimg($textarea, $rs, $thisurl = "",$notclfdl=0)
    {
        if ($rs[loadimg]&&!$notclfdl) {
            $r = ($rs[refresh]) ? "&r=" . urlencode($thisurl) : "";
            $c = ($rs[c]) ? "&c=1" : "";
            $textarea = preg_replace("/\[img\](?!http\:\/\/collect\.longsunhd\.com)(.*)\[\/img\]/Uisxe", '"[img]http://collect.longsunhd.com/source/plugin/yzs1013_pldr/getimg.php?url=".surlencode("\\1").$r.$c."[/img]"', $textarea);
        }
        return $textarea;
    }

    function curl3($post, $cookie = "")
    {
        $POSTFIELDS = "";

        if (substr($post, 0, 7) == "http://") {
            $post = urltopoststr2($post, $cookie);
        }

        preg_match_all("/^Host\:(\s*.*)$/Uimx", $post, $nn);
        $host = trim(chop($nn[1][0]));
        $site = "http://" . $host;
        preg_match_all("/^(POST|GET)\s+(.*)\s+HTTP/Umx", $post, $uu);
        $url = preg_replace("/\/+$/", "", $site) . "/" . preg_replace("/^\/+/", "", chop($uu[2][0]));
        preg_match_all("/^Referer\:(\s*.*)$/Uimx", $post, $nn);
        $Referer = trim(chop($nn[1][0]));
        preg_match_all("/(?:\r\n\r\n|\n\n)(.*)$/Uis", $post, $nn);
        $Querystring = trim(chop($nn[1][0]));
        preg_match_all("/boundary=(.*)$/Uim", $post, $nn);
        $boundary = trim(chop($nn[1][0]));
        $filename = $url;
        //$filename=$url.(preg_match("/\?/",$url)?"&":"?").$Querystring;
        //$filename=preg_replace("/http\:\/\/[^\/]*\//Uisx","/",$filename);
        $user_agent = "Mozilla/99.99 (compatible; MSIE 99.99; Windows XP 99.99)";
        $POSTFIELDS = $Querystring;

        $ch = curl_init();


        $timeout = 60;
        curl_setopt($ch, CURLOPT_URL, $filename);
        //curl_setopt ($ch, CURLOPT_MUTE, 0);
        curl_setopt($ch, CURLOPT_VERBOSE, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0");
        curl_setopt($ch, CURLOPT_HEADER, 1); //要求输出头信息
        if ($uu[1][0] == "POST") curl_setopt($ch, CURLOPT_POST, 1);
        if (preg_match("/multipart/Uisx", $post)) {
            curl_setopt($ch, CURLOPT_VERBOSE, 1);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data; boundary=$boundary"));
            //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        }
        if ($Referer != "") curl_setopt($ch, CURLOPT_REFERER, $Referer);
        if ($cookie != "") curl_setopt($ch, CURLOPT_COOKIE, $cookie);
        if ($Querystring != "" && $uu[1][0] == "POST") {
            curl_setopt($ch, CURLOPT_POSTFIELDS, $Querystring);
        }
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $result = curl_exec($ch);
        curl_close($ch);

        preg_match("/(^.*)(?:\r\n\r\n|\n\n)(.*?)$/Uis", $result, $nn);
        $header = $nn[1];
        $body = $nn[2];

        if (@gzinflate(substr($body, 10))) {
            $body = @gzinflate(substr($body, 10));
        }


        //---------------解chunk编码

        if (strpos($result, 'chunk')) {
            $tmpfile = tempnam('/tmp', 'webcache');
            $fp = fopen($tmpfile, 'w');
            fwrite($fp, $result);
            fclose($fp);
            ob_start();
            readgzfile($tmpfile);
            $result = ob_get_contents();
            ob_end_clean();
            unlink($tmpfile);
        }

        $result = $header . "\r\n\r\n" . $body;
        $nr = $result;
        //$nr=preg_replace("/<(\/?script[^>]*)>/Uisx","<!--\\1-->",$nr);
        return $nr;
    }

    function chunk($result)
    {
        if (@gzinflate(substr($result, 10))) {
            $result = @gzinflate(substr($result, 10));
        }
        if (strpos($result, 'chunk')) {
            $tmpfile = tempnam('/tmp', 'webcache');
            $fp = fopen($tmpfile, 'w');
            fwrite($fp, $result);
            fclose($fp);
            ob_start();
            readgzfile($tmpfile);
            $result = ob_get_contents();
            ob_end_clean();
            unlink($tmpfile);
        }
        return $result;
    }

    function curl4($post, $cookie = "")
    {
        $POSTFIELDS = "";

        preg_match_all("/^Host\:(\s*.*)$/Uimx", $post, $nn);
        $host = trim(chop($nn[1][0]));
        $site = "http://" . $host;
        preg_match_all("/^(POST|GET)\s+(.*)\s+HTTP/Umx", $post, $uu);
        $url = preg_replace("/\/+$/", "", $site) . "/" . preg_replace("/^\/+/", "", chop($uu[2][0]));
        preg_match_all("/^Referer\:(\s*.*)$/Uimx", $post, $nn);
        $Referer = trim(chop($nn[1][0]));
        preg_match_all("/\r\n\r\n(.*)$/Uis", $post, $nn);
        $Querystring = trim(chop($nn[1][0]));
        preg_match_all("/boundary=(.*)$/Uim", $post, $nn);
        $boundary = trim(chop($nn[1][0]));
        $filename = $url;
        //$filename=$url.(preg_match("/\?/",$url)?"&":"?").$Querystring;
        $user_agent = "Mozilla/99.99 (compatible; MSIE 99.99; Windows XP 99.99)";
        $POSTFIELDS = $Querystring;

        $ch = curl_init();

        $timeout = 60;
        curl_setopt($ch, CURLOPT_URL, $filename);
        //curl_setopt ($ch, CURLOPT_MUTE, 0);
        curl_setopt($ch, CURLOPT_VERBOSE, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/99.99 (compatible; MSIE 99.99; Windows XP 99.99)");
        curl_setopt($ch, CURLOPT_HEADER, 0); //要求输出头信息
        if ($uu[1][0] == "POST") curl_setopt($ch, CURLOPT_POST, 1);
        if (preg_match("/multipart/Uisx", $post)) {
            curl_setopt($ch, CURLOPT_VERBOSE, 1);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data; boundary=$boundary"));
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        }
        if ($Referer != "") curl_setopt($ch, CURLOPT_REFERER, $Referer);
        if ($cookie != "") curl_setopt($ch, CURLOPT_COOKIE, $cookie);
        if ($Querystring != "" && $uu[1][0] == "POST") {
            curl_setopt($ch, CURLOPT_POSTFIELDS, $Querystring);
        }

        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

        $result = @curl_exec($ch);
        curl_close($ch);

        preg_match_all("/(^.*)\r\n\r\n(.*?)$/Uis", $result, $nn);
        $header = $nn[1];
        $body = $nn[2];
        if (@gzinflate(substr($body, 10))) {
            $result = @gzinflate(substr($nn[2][0], 10));
        }
        //$result=$body;
        $nr = $result;
        //$cookie=getcookie($result);
        //setcookieto();
        //$nr=preg_replace("/<(\/?script[^>]*)>/Uisx","<!--\\1-->",$nr);
        return $nr;
    }

    if (!function_exists('urltopoststr2')) {
        function urltopoststr2($post, $cookies)
        {
            $publicpoststr = <<<TEXT
GET {surl} HTTP/1.1
Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/QVOD, application/QVOD, * / *
Accept-Language: zh-CN
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; Foxy/1; QQDownload 702; GTB7.2; Foxy/1; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C)
Accept-Encoding: gzip, deflate
cookies:{cookies}
Proxy-Connection: Keep-Alive
Host: {host}


TEXT;
            preg_match_all("/(http\:\/\/([^\/]*?))(.*)$/Uimx", $post, $mm);
            $host = $mm[2][0];
            $surl = $mm[3][0];
            $publicpoststr = str_replace("{host}", $host, $publicpoststr);
            $publicpoststr = str_replace("{surl}", $surl, $publicpoststr);
            $publicpoststr = str_replace("{cookies}", $cookies, $publicpoststr);
            return trim($publicpoststr) . "\r\n\r\n";
        }
    }

    /**分析nn
     * @param $textarea
     * @param $thisurl
     * @param array $params
     * @param array $rs
     * @param string $thisbaseurl
     * @param string $thissecexe
     * @return mixed|string
     */
    function evalpublic(&$textarea, $thisurl, $params = array(), $rs = array(), $thisbaseurl = "", $thissecexe = "")
    {
        global $nn55;
        $nn221 = $nn44 = $nn11 = $nn12 = $nn111 = $nn99 = $nn91 = $nn92 = $nn222 = array();
        extract($params);
        foreach ($params as $k => $v) {
            if (is_array($v)) {
                if (function_exists($k)) {
                    $v = call_user_func($k, $v);
                }
            }
        }
        $returntextarea = $textarea;
        if (count($nn221[1]) > 0) {
            $returntextarea = "";
            $nn22 = $nn221;
        }
        if (count($nn22[1]) > 0) {
            $tempstr = "";
            for ($i = 0; $i < count($nn22[1]); $i++) {
                $nn22[1][$i] = utf8encode($nn22[1][$i]);
                $nn22[2][$i] = utf8encode($nn22[2][$i]);
                if ($nn22[url][$i] != "" || $nn22['title'][$i] != "") {
                    $url = urldecode($nn22['url'][$i]);
                    $title = urldecode($nn22['title'][$i]);
                } else {
                    if (preg_match("/(^http[^<>\s]*(?:jpg|jpeg|gif|png|bmp)|\.[a-zA-Z0-9]+(?:jpg|jpeg|gif|png|bmp)$)/Uisx", $nn22[1][$i], $nn)) {
                        $url = $nn22[1][$i];
                        $title = $nn22[2][$i];
                    } else {
                        $url = $nn22[2][$i];
                        $title = $nn22[1][$i];
                    }
                }
                $url = str_replace('\/', "/", trim($url));
                $url = preg_replace("/_small\.jpg/Uisx", ".jpg", trim($url));
                $url = preg_replace("/thumb_[0-9]+_[0-9]+_/Uisx", "", trim($url));
                $tempstr .= createimgubb($url, $title, $rs['loadimg'], $thisurl, $thisbaseurl);
            }
            $tempstr = deletePublic($tempstr, $thisurl, 0);
            $returntextarea = (maxlen($tempstr) > maxlen($textarea)) ? $tempstr : $textarea . $tempstr;
            $a = 1;
        }

        if (count($nn44[1]) > 0) {
            $tempstr = "";
            for ($i = 0; $i < count($nn44[1]); $i++) {
                $nn44[1][$i] = utf8encode($nn44[1][$i]);
                $nn44[2][$i] = utf8encode($nn44[2][$i]);
                if (preg_match("/(^http[^<>\s]*|\.[a-zA-Z0-9]+$)/Uisx", $nn44[1][$i], $nn)) {
                    $url = $nn44[1][$i];
                    $title = $nn44[2][$i];
                } else {
                    $url = $nn44[2][$i];
                    $title = $nn44[1][$i];
                }
                $hz = (!preg_match("/\?/", $url)) ? "?" . $nn44[3][$i] : "&" . $nn44[3][$i];

                if (preg_match("/swf|flv/i", $url)) {
                    $tempstr .= "[flash]" . quanurl($url, $thisurl, $thisbaseurl) . $hz . "[/flash]\r\n" . $title . "\r\n";
                } else if (preg_match("/jpg|png/i", $url)) {
                    $tempstr .= "[img]" . quanurl($url, $thisurl, $thisbaseurl) . $hz . "[/img]\r\n" . $title . "\r\n";
                }else{
                    $tempstr .= "[img]" . quanurl($url, $thisurl, $thisbaseurl) . $hz . "[/img]\r\n" . $title . "\r\n";
                }
            }
            $tempstr = deletePublic($tempstr, $thisurl, 0);
            $returntextarea = (maxlen($tempstr) > maxlen($textarea)) ? $tempstr : $tempstr . "\r\n" . $textarea;
            $a = 1;
        }


        if (count($nn55[1]) > 0) {
            $tempstr = "";
            $inarr = array();
            $newnn55 = array();
            for ($i = 0; $i < count($nn55[1]); $i++) {
                if ($nn55['name'] != "") {
                    $name = $nn55['name'][$i];
                    $value = $nn55['value'][$i];
                } else {
                    if (is_array($nn55[2][$i]) && count($nn55[2][$i]) > 0) {
                        $name = $nn55[1][$i];
                        $value = $nn55[2][$i];
                    } else {
                        if (preg_match("/\:|：|<(?:B|strong)>/Uisx", $nn22[2][$i], $nn)) {
                            $name = $nn55[2][$i];
                            $value = $nn55[1][$i];
                        } else {
                            $name = $nn55[1][$i];
                            $value = $nn55[2][$i];
                        }
                        $name = utf8encode($name);
                        $value = utf8encode($value);
                    }
                }
                $name = clzdname($name);
                if (in_array($name, $inarr)) {
                    continue;
                } else {
                    $inarr[] = $name;
                }
                $value = clzdvalue($value);
                if ($value != "" && $name != "") {
                    $tempstr .= "\r\n[b]【" . $name . "】[/b]:" . $value;
                }
                if ($i > 2) $newnn55[0][$name] = $value;
            }
            $GLOBALS['nn55'] = $newnn55;
            $tempstr = deletePublic($tempstr, $thisurl, 0);
            $returntextarea = $tempstr . "\r\n" . $textarea;
            $a = 1;
        }

        if (count($nn11[1]) > 0) {
            for ($i = 0; $i < count($nn11[1]); $i++) {
                $nr = $nn11[1][$i];
                $nr = preg_replace("/_small\.jpg/Uisx", ".jpg", $nr);
                $nr = preg_replace("/thumb_[0-9]+_[0-9]+_/Uisx", "", $nr);
                if (trim($nr) != "") {
                    if (preg_match("/\.(jpg|png|gif|jpeg)\s*(?<!html?)$/i", $nr)) {
                        $returntextarea = "\r\n" . trim(createimgubb($nr, $title, $rs[loadimg], $thisurl, $thisbaseurl)) . "\r\n" . $returntextarea;
                    } else {
                        $returntextarea = deletePublic($nr, $thisurl, 0) . "\r\n" . $returntextarea;
                    }
                }
            }
        }

        if (count($nn12[1]) > 0) {
            for ($i = 0; $i < count($nn01[1]); $i++) {
                $nr = $nn01[1][$i];
                $nr = preg_replace("/_small\.jpg/Uisx", ".jpg", $nr);
                $nr = preg_replace("/thumb_[0-9]+_[0-9]+_/Uisx", "", $nr);
                if (trim($nr) != "") {
                    if (preg_match("/\.(jpg|png|gif|jpeg)\s*(?<!html?)$/i", $nr)) {
                        $returntextarea = $returntextarea."\r\n" . trim(createimgubb($nr, $title, $rs[loadimg], $thisurl, $thisbaseurl)) ;
                    } else {
                        $returntextarea = $returntextarea."\r\n" . deletePublic($nr, $thisurl, 0) ;
                    }
                }
            }
        }


        if (count($nn111) > 0) {
            $returntextarea = "";
            for ($i = 0; $i < count($nn111); $i++) {
                $nr = $nn111[$i];
                $nr = preg_replace("/_small\.jpg/Uisx", ".jpg", $nr);
                $nr = preg_replace("/thumb_[0-9]+_[0-9]+_/Uisx", "", $nr);
                if (trim($nr) != "") {
                    if (preg_match("/\.(jpg|png|gif|jpeg)\s*$/i", $nr)) {
                        $returntextarea .= "\r\n" . trim(createimgubb($nr, $title, $rs[loadimg], $thisurl, $thisbaseurl)) . "\r\n\r\n" . $nn222[$i] . "\r\n";
                    } else {
                        $returntextarea .= "\r\n" . trim(createimgubb($nn222[$i], $title, $rs[loadimg], $thisurl, $thisbaseurl)) . "\r\n" . clwz(strip_tags($nr)) . "\r\n\r\n";
                    }
                }
            }
        }

        if (count($nn99[1]) > 0) {
            //echo quanurl($nn99[1][0],$thisurl)."\r\n";
            $nr = redo(quanurl($nn99[1][0], $thisurl, $thisbaseurl), $thissecexe);
            if (trim($nr) != "") $returntextarea .= $nr;
        }

        if (count($nn91[0]) > 0) {
            $nr = redo(quanurl($nn91[0], $thisurl, $thisbaseurl), $thissecexe);
            if (trim($nr) != "") $returntextarea = $nr . $returntextarea;
        }

        if (count($nn92[0]) > 0) {
            $nr = redo(quanurl($nn92[0], $thisurl, $thisbaseurl), $thissecexe);
            if (trim($nr) != "") $returntextarea = $returntextarea . $nr;
        }

        $textarea = $returntextarea;
        return $returntextarea;
    }

    function createimgubb($url, $title, $loadimg, $thisurl, $thisbaseurl = "")
    {
        $title2 = utf8encode($title);
        $textarea = "";
        if ($url != "") {
            if ($loadimg) {
                $url = str_replace("%", "BAIFENHAO", $url);
                $textarea = "[img]http://collect.longsunhd.com/source/plugin/yzs1013_pldr/getimg.php?url=" . surlencode(quanurl(trim($url), $thisurl, $thisbaseurl)) . "[/img]";
            } else {
                $textarea = "[img]" . quanurl(trim($url), $thisurl, $thisbaseurl) . "[/img]";
            }
        }

        if (preg_match("/^http\:\/\//Uisx", $title)) {
            $textarea = trim($textarea) . "\r\n[url={$title2}]" . $title2 . "[/url]\r\n";
        } else {
            $textarea = "\r\n{$textarea}\r\n{$title2}\r\n";
        }
        return $textarea;
    }

    function dore($re, $tempnr = "", $ytempnr = "", $thisurl = "", $rs = array())
    {
        global $news;
        $textarea = "";
        $bug = 0;
        $nn22 = $nn221 = $nn11 = array();
        $cc = preg_split("/\|\|\||$/m", $re);
        for ($i = 0; $i < count($cc); $i++) {
            if (trim($cc[$i]) == "") continue;
            if (!preg_match("/\&\&\&/Uisx", $cc[$i])) {
                if (preg_match("/\:y(?=$|\:)/Uisx", trim($cc[$i]))) {
                    $cc[$i] = preg_replace("/\:y(?=$|\:)/", "", $cc[$i]);
                    $tempnr = $ytempnr;
                }
                if (preg_match("/\:nn([0-9]+)(?=$|\:)/Uisx", trim($cc[$i]), $mm4)) {
                    $cc[$i] = preg_replace("/\:nn[0-9]+(?=$|\:)/Uisx", "", trim($cc[$i]));
                    $cc[$i] = (!isutf8($cc[$i])) ? u(trim($cc[$i])) : trim($cc[$i]);
                    preg_match_all("/" . trim($cc[$i]) . "/Uisx", $tempnr, ${"nn" . $mm4[1]});
                } else {
                    if (trim($textarea) == "") {
                        $cc[$i] = (!isutf8($cc[$i])) ? u(trim($cc[$i])) : trim($cc[$i]);
                        preg_match_all("/" . trim($cc[$i]) . "/Uisx", $tempnr, $nn);
                        $textarea = trim($nn[1][0]);
                    }
                }
            } else {
                $ddd = explode("&&&", $cc[$i]);
                $tempnr2 = $tempnr;
                if (count($ddd) > 1) {
                    for ($d = 0; $d < count($ddd) - 1; $d++) {
                        preg_match_all("/" . trim($ddd[$d]) . "/Uisx", $tempnr2, $nn);
                        $tempnr2 = $nn[1][0];
                        //echo trim($ddd[$d]).$tempnr2;
                    }


                    if (preg_match("/\:nn([0-9]+)(?=\:|$)/Uisx", trim($ddd[count($ddd) - 1]), $mm4)) {
                        $ddd[count($ddd) - 1] = preg_replace("/\:nn[0-9]+(?=\:|$)/Uisx", "", trim($ddd[count($ddd) - 1]));
                        preg_match_all("/" . trim($ddd[count($ddd) - 1]) . "/Uisx", $tempnr, ${"nn" . $mm4[1]});
                    }
                }
            }

        }

        $oo = ${"nn" . $mm4[1]};

        if (count($oo) > 0) {
            $params = array("nn22" => $nn22, "nn221" => $nn221, "nn11" => $nn11);
            $textarea .= evalpublic($textarea, $thisurl, $params, $rs, $bug);
        }
        return $textarea;
    }

    function surlencode($url)
    {
        if (preg_match("/http%3A%2F%2F/Uisx", $url)) {
            return $url;
        }
        $url = urlencode(str_replace("%", "BAIFENHAO", $url));
        return $url;
    }

    function replacedxkh($nr)
    {
        $nr = str_replace("<", "&lt;", $nr);
        $nr = str_replace(">", "&gt;", $nr);
        return $nr;
    }

    function loopbz($nr, $divre = "<div[^<>]*class=\"spaceborder\"[^<>]*>", $firstre = "<img[^<>]*src=\"([^<>]*(uface|userface)[^<>]*)\"[^<>]*>", $contentre = "<div\s+class=\"bshare\-image2share\"[^<>]*>(.*)<span")
    {
        $first = $textarea = "";
        preg_match_all("/($divre)(.*)(?=$divre)/Uisx", $nr, $nn);
        for ($i = 0; $i < count($nn[1]); $i++) {
            if (preg_match("/$firstre/Uisx", $nn[0][$i], $mm) && $first == "") {
                //echo 4;
                $first = $mm[0];
                if ($contentre != "") {
                    preg_match("/$contentre/Uisx", $nn[0][$i], $mm2);
                    $textarea .= $mm2[1];
                } else {
                    $textarea .= $nn[0][$i];
                }
            } elseif ($first != "" && preg_match("/" . addsla($first) . "/Uisx", $nn[0][$i])) {
                echo 5;
                if ($contentre != "") {
                    preg_match("/$contentre/Uisx", $nn[0][$i], $mm2);
                    $textarea .= $mm2[1];
                } else {
                    $textarea .= $nn[0][$i];
                }
            }

        }
        return $textarea;
    }


    function utf8_unicode2($str)
    {
        $temp = "";
        preg_match_all("/[\x80-\xff]?./", $str, $ar);
        foreach ($ar[0] as $v)
            //$temp.="&#".utf8_unicode($v).";";
            //$temp.="&amp;#".utf8_unicode(iconv("GB2312","UTF-8",$v)).";";
            $temp .= "&#" . utf8_unicode($v) . ";";
        return $temp;
    }


    function jsstart($name = 'default')
    {
        global $ss_timing_start_times;
        $ss_timing_start_times[$name] = explode(" ", microtime());
    }

    function jsstop($name = 'default')
    {
        global $ss_timing_stop_times;
        $ss_timing_stop_times[$name] = explode(" ", microtime());
    }

    function js($name = 'default')
    {
        global $ss_timing_start_times, $ss_timing_stop_times;
        if (!isset($ss_timing_start_times[$name])) {
            return 0;
        }
        if (!isset($ss_timing_stop_times[$name])) {
            $stop_time = explode(" ", microtime());
        } else {
            $stop_time = $ss_timing_stop_times[$name];
        }
        $current = $stop_time[1] - $ss_timing_start_times[$name][1];
        $current += $stop_time[0] - $ss_timing_start_times[$name][0];
        return $current;
    }


    function swfhost($nr, $thisurl, &$swfstr, $host)
    {
        switch ($host) {
            case "sina.com.cn":
                if (preg_match("/vid\s*=\"([0-9]+)\"/isx", $nr, $nn)) {
                    $vid = $nn[1];
                }
                if (preg_match("/vid\s*\:\'([0-9]+)\'\,/Uisx", $nr, $nn)) {
                    $vid = $nn[1];
                }
                if (preg_match("/uid\s*\:\'([0-9]+)\'\,/Uisx", $nr, $nn)) {
                    $uid = $nn[1];
                }
                if (preg_match("/sid\s*\:\'([0-9]+)\'\,/Uisx", $nr, $nn)) {
                    $sid = $nn[1];
                }
                if (preg_match("/tid\s*\:\'([0-9]+)\'\,/Uisx", $nr, $nn)) {
                    $tid = $nn[1];
                }
                if (preg_match("/pid\s*\:\'([0-9]+)\'\,/Uisx", $nr, $nn)) {
                    $pid = $nn[1];
                }
                $uid = ($uid == "") ? 6 : $uid;
                $tid = ($tid == "") ? 2 : $tid;
                $pid = ($pid == "") ? 1 : $pid;
//echo "http://v.iask.com/v_play.php?vid={$vid}&uid={$uid}&pid={$pid}&tid={$tid}&referrer=&ran=0.2793316".rand(1000,9999)."28716&r=video.sina.com.cn";
                $nr = curl_file_get_contents("http://v.iask.com/v_play.php?vid={$vid}&uid={$uid}&pid={$pid}&tid={$tid}&referrer=&ran=0.2793316" . rand(1000, 9999) . "28716&r=video.sina.com.cn");
                if (preg_match("/<url><\!\[CDATA\[(.*)\]\]><\/url>/Uisx", $nr, $nn)) {
                    $url = $nn[1];
                }
                return $url;
                break;
        }
    }

    function unicode_decode($name)
    {
        $name = trim($name);
        $name = preg_replace("/[\\\\\\|\/]?u([0-9a-zA-Z]{4})/ie", 'zh2("\\1")', $name); //%u\\1
        $name = preg_replace("/(\\\u([0-9a-z]{1,4}))/ie", 'zh("\\1")', $name);
        $name = unicode_decode2($name);
        return $name;
    }

    function unicode_decode_utf8($name)
    {
        $name = unicode_decode(trim($name));
        $name = mb_convert_encoding($name, "gb2312", "UTF-8");
        return $name;
    }


    function unicode_decode0($name)
    {
        $name = trim($name);
        $name = preg_replace("/[\\\\\\|\/]?u([0-9a-zA-Z]{4})/ie", 'zh2("\\1")', $name); //%u\\1
        return $name;
    }

    function unicode_decode1($name)
    {
        $name = trim($name);
        $name = preg_replace("/[\\\\\\|\/]?u([0-9a-zA-Z]{4})/ie", 'zh2("\\1")', $name); //%u\\1
        $name = preg_replace("/(\\\u([0-9a-z]{1,4}))/ie", 'zh("\\1")', $name);
        $name = unicode_decode2($name);
        return $name;
    }

    function zh($str)
    {
        $code = base_convert(substr($str, 2, 2), 16, 10);
        $code2 = base_convert(substr($str, 4), 16, 10);
        $c = chr($code) . chr($code2);
        $c = iconv('UCS-2', 'GB2312//IGNORE', $c);
        return $c;
    }

    function zh2($str)
    {
        $c = "&#x" . $str . ";";
        return $c;
    }

    function unicode_decode2($str)
    {
        $str = rawurldecode($str);
        preg_match_all("/(?:%u.{4})|&#x.{4};|&#\d+;|.+/U", $str, $r);
        $ar = $r[0];
        foreach ($ar as $k => $v) {
            if (substr($v, 0, 2) == "%u")
                $ar[$k] = @iconv("UCS-2", "GB2312", pack("H4", substr($v, -4)));
            elseif (substr($v, 0, 3) == "&#x")
                $ar[$k] = @iconv("UCS-2", "GB2312", pack("H4", substr($v, 3, -1)));
            elseif (substr($v, 0, 2) == "&#") {
                $ar[$k] = @iconv("UCS-2", "GB2312", pack("n", substr($v, 2, -1)));
            }
        }
        return join("", $ar);
    }


    function isint($str)
    {
        return preg_match("/^[0-9]+$/", $str);
    }

    function r($nr)
    {
        $fn = fopen("d:/TMPTMP_ytempnr.htm", "w");
        fwrite($fn, $nr);
        fclose($fn);
    }

    function maxlen($arr)
    {
        $temp = "";
        $arr = ($arr = null) ? "" : $arr;
        if (is_array($arr)) {
            for ($i = 0; $i < count($arr); $i++) {
                if (strlen(strim($arr[$i])) > strlen(strim($temp))) {
                    $temp = $arr[$i];
                }
            }
        } elseif (is_string($arr)) {
            if (strlen(strim($arr)) > strlen(strim($temp))) {
                $temp = $arr;
            }
        }
        return strlen($temp);
    }

    function strim($str)
    {
        $str = preg_replace("/\s|　/", "", preg_replace("/<\/?(?!img|br)[^<>]*>/i", "", $str));
        return $str;
    }

    function getNextPage($rearr, $nr)
    {
        if (is_array($rearr) && count($rearr) > 0) {
            for ($pp = 0; $pp < count($rearr); $pp++) {
                if (preg_match("/" . $rearr[$pp] . "/Uisx", $nr, $mm)) {
                    if (function_exists('nn88')) {
                        $mm[1] = nn88($mm[1]);
                    }
                    $mm[1] = str_replace('&amp;', '&', $mm[1]);
                    $return = $mm[1];
                    break;
                }
            }
        }
        return $return;
    }

    function renrarray($re, $nr, $array)
    {
        if (preg_match("/" . trim($re) . "/Uisx", $nr, $nn)) {
            for ($i = 0; $i < count($array); $i++) {
                $GLOBALS[$array[$i]] = $nn[$i + 1];
            }
        }
    }

    function preg_count($re, $nr, &$nn = array())
    {
        preg_match_all("/(" . trim($re) . ")/Uisx", $nr, $nn);
        return count($nn[0]);
    }

    function is_zw($str)
    {
        $str = preg_replace("/[\r\n]|$|<(?!img)[^<>]*>/Uisx", "", $str);
        if (preg_match_all("/([\x{4e00}-\x{9fa5}]|。|，|？|！|[^<>\/\\\]){20,}/Uisxu", $str, $nn) || preg_count("\[img\]|<img|。|，|？|！", $str) > 1 || preg_match("/<img[^<>]*|\[img\]/Uisx", $str)) {
            return true;
        }
        return false;
    }

    function array_merge2($arr1, $arr2)
    {
        if (count($arr1) < count($arr2)) {
            $t = $arr1;
            $arr1 = $arr2;
            $arr2 = $t;
        }
        $newarr = $arr1;
        for ($i = 0; $i < count($arr1); $i++) {
            if (is_array($arr2[$i])) $newarr[$i] = array_merge($arr1[$i], $arr2[$i]);
        }
        return $newarr;
    }

    function curlbase($url, $cookie = "")
    {
        static $cookie;
        $host = whost($url);
        $Referer = "http://{$host}/";

        $timeout = 15;
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)");
        curl_setopt($ch, CURLOPT_HEADER, 1);
        //curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        /*if(preg_match("/multipart/Uisx",$post)){
            curl_setopt($ch, CURLOPT_VERBOSE, 1);
            curl_setopt( $ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data; boundary=$boundary"));
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        }*/
        if ($Referer != "") curl_setopt($ch, CURLOPT_REFERER, $Referer);
        if ($cookie != "") curl_setopt($ch, CURLOPT_COOKIE, $cookie);
        //if ($Querystring != "" && $uu[1][0] == "POST") {
        //    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
        //    curl_setopt($ch, CURLOPT_POSTFIELDS, $Querystring);
        //}

        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $result = curl_exec($ch);
        curl_close($ch);
        preg_match("/set\-cookie\:\s*([^\s]*)/", $result, $nn);
        $cookie = $nn[1];
        preg_match("/(^.*)(?:\r\n\r\n|\n\n)(.*?)$/Uis", $result, $nn);
        $result = $nn[2];
        if (@gzinflate(substr($result, 10))) {
            $result = gzinflate(substr($result, 10));
        }
        return $result;
    }

    function pagebug($news, $re, $nexturl)
    {
        r($news->url . "\r\n" . $re . "\r\nNextUrl:" . $nexturl . "\r\n\r\n" . $news->yuannr . g($news->yuannr));
    }

    /**
     * 将字符串转换成unicode编码
     *
     * @param string $input
     * @param string $input_charset
     * @return string
     */
    function str_to_unicode($input, $input_charset = 'gbk')
    {
        $input = iconv($input_charset, "gbk", $input);
        preg_match_all("/[\x80-\xff]?./", $input, $ar);
        $b = array_map('utf8_unicode_', $ar[0]);
        $outstr = join("", $b);
        return $outstr;
    }

    function utf8_unicode_($c, $input_charset = 'gbk')
    {
        $c = iconv($input_charset, 'utf-8', $c);
        return utf8_unicode($c);
    }

// utf8 -> unicode
    function utf8_unicode($c)
    {
        switch (strlen($c)) {
            case 1:
                return $c;
            case 2:
                $n = (ord($c[0]) & 0x3f) << 6;
                $n += ord($c[1]) & 0x3f;
                break;
            case 3:
                $n = (ord($c[0]) & 0x1f) << 12;
                $n += (ord($c[1]) & 0x3f) << 6;
                $n += ord($c[2]) & 0x3f;
                break;
            case 4:
                $n = (ord($c[0]) & 0x0f) << 18;
                $n += (ord($c[1]) & 0x3f) << 12;
                $n += (ord($c[2]) & 0x3f) << 6;
                $n += ord($c[3]) & 0x3f;
                break;
        }
        return "&#$n;";
    }

    /**
     * 将unicode字符转换成普通编码字符
     *
     * @param string $str
     * @param string $out_charset
     * @return string
     */
    function str_from_unicode($str, $out_charset = 'gbk')
    {
        $str = preg_replace_callback("|&#([0-9]{1,5});|", 'unicode2utf8_', $str);
        $str = iconv("UTF-8", $out_charset, $str);
        return $str;
    }

    function unicode2utf8_($c)
    {
        return unicode2utf8($c[1]);
    }

    function unicode2utf8($c)
    {
        $str = "";
        if ($c < 0x80) {
            $str .= $c;
        } else if ($c < 0x800) {
            $str .= chr(0xC0 | $c >> 6);
            $str .= chr(0x80 | $c & 0x3F);
        } else if ($c < 0x10000) {
            $str .= chr(0xE0 | $c >> 12);
            $str .= chr(0x80 | $c >> 6 & 0x3F);
            $str .= chr(0x80 | $c & 0x3F);
        } else if ($c < 0x200000) {
            $str .= chr(0xF0 | $c >> 18);
            $str .= chr(0x80 | $c >> 12 & 0x3F);
            $str .= chr(0x80 | $c >> 6 & 0x3F);
            $str .= chr(0x80 | $c & 0x3F);
        }
        return $str;
    }

    /**
     * 模拟JS里的unescape
     *
     * @param unknown_type $str
     * @return unknown
     */
    function unescape($str)
    {
        $str = rawurldecode($str);
        preg_match_all("/(?:(?:%u.{4})|.{4};|&#\d+;|.+/U", $str, $r);
        $ar = $r[0];
        #print_r($ar);
        foreach ($ar as $k => $v) {
            if (substr($v, 0, 2) == "%u")
                $ar[$k] = iconv("UCS-2", "GB2312", pack("H4", substr($v, -4)));
            elseif (substr($v, 0, 3) == "")
                $ar[$k] = iconv("UCS-2", "GB2312", pack("H4", substr($v, 3, -1)));
            elseif (substr($v, 0, 2) == "&#") {
                echo substr($v, 2, -1) . "
";
                $ar[$k] = iconv("UCS-2", "GB2312", pack("n", substr($v, 2, -1)));
            }
        }
        return join("", $ar);
    }


    function utf8encode($source)
    {
        $source=urldecode($source);
        if (is_string($source)) {
            if (!preg_match("/\\\u[a-z0-9]{4}|%u[a-z0-9]{4}|\&\#[a-z0-9]{4,5}/", $source)) {
                return $source;
            }
        }

        $utf8str = '';
        $source = preg_replace('/\\\u/', '%u', $source);
        $source = convert_entities($source);
        $entities = explode('&#', $source);
        $size = count($entities);

        for ($i = 0; $i < $size; $i++) {
            $foo = $entities[$i];
            $nonEntity = strstr($foo, ';');

            if ($nonEntity !== false) {
                $unicode = intval(substr($foo, 0, (strpos($foo, ';') + 1)));
                // determine how many chars are needed to reprsent this unicode char
                if ($unicode < 128) {
                    $bar = chr($unicode);
                } else if ($unicode >= 128 and $unicode < 2048) {
                    $binVal = str_pad(decbin($unicode), 11, '0', STR_PAD_LEFT);
                    $binPart1 = substr($binVal, 0, 5);
                    $binPart2 = substr($binVal, 5);

                    $char1 = chr(192 + bindec($binPart1));
                    $char2 = chr(128 + bindec($binPart2));
                    $bar = $char1 . $char2;
                } else if ($unicode >= 2048 and $unicode < 65536) {
                    $binVal = str_pad(decbin($unicode), 16, '0', STR_PAD_LEFT);
                    $binPart1 = substr($binVal, 0, 4);
                    $binPart2 = substr($binVal, 4, 6);
                    $binPart3 = substr($binVal, 10);

                    $char1 = chr(224 + bindec($binPart1));
                    $char2 = chr(128 + bindec($binPart2));
                    $char3 = chr(128 + bindec($binPart3));
                    $bar = $char1 . $char2 . $char3;
                } else {
                    $binVal = str_pad(decbin($unicode), 21, '0', STR_PAD_LEFT);
                    $binPart1 = substr($binVal, 0, 3);
                    $binPart2 = substr($binVal, 3, 6);
                    $binPart3 = substr($binVal, 9, 6);
                    $binPart4 = substr($binVal, 15);

                    $char1 = chr(240 + bindec($binPart1));
                    $char2 = chr(128 + bindec($binPart2));
                    $char3 = chr(128 + bindec($binPart3));
                    $char4 = chr(128 + bindec($binPart4));
                    $bar = $char1 . $char2 . $char3 . $char4;
                }

                if (strlen($nonEntity) > 1) {
                    $nonEntity = substr($nonEntity, 1); // chop the first char (';')
                } else {
                    $nonEntity = '';
                }
                $utf8str .= $bar . $nonEntity;
            } else {
                $utf8str .= $foo;
            }
        }
        $utf8str = preg_replace("/(\\\\)+n/", "", $utf8str);
        $utf8str = preg_replace("/(\\\\)+n/", "", $utf8str);
        if (preg_match("/http\:\\\\\/\\\\\//", $utf8str)) {
            //$utf8str = stripcslashes($utf8str);
        }
        return $utf8str;
    }

    function convert_entities($str)
    {
        $str = preg_replace_callback('|%u([a-f0-9]{4})|i',
            create_function(
                '$matches',
                'return \'&#\' . hexdec($matches[1]) . \';\';'
            ),
            $str
        );
        return $str;
    }

    function lu2utf8($source)
    {
        return utf8encode($source);
    }

    function print_r2($arr)
    {
        $newarr = array();
        foreach ($arr as $k => $v) {
            if (is_array($v)) {
                foreach ($v as $k2 => $v2) {
                    $newarr[$k][$k2] = utf8encode($v2);
                }
            } elseif (is_string($v)) {
                $newarr[$k] = utf8encode($v);
            }
        }
        $return = print_r($newarr, 1);
        r($return);
        return $return;
    }

    function clwzarray($nn, $thisurl, $clhc)
    {
        $newarr = array();
        foreach ($nn as $k => $v) {
            if (is_array($v)) {
                foreach ($v as $k2 => $v2) {
                    $newarr[$k][$k2] = deletePublic(utf8encode($v2), $thisurl, $clhc);
                }
            } elseif (is_string($v)) {
                $newarr[$k] = deletePublic(utf8encode($v), $thisurl, $clhc);
            }
        }
        return $newarr;

    }

    function danweiarray($array)
    {
        $newarr = array();
        foreach ($array as $k => $v) {
            $newarr[$k] = $v[0];
        }
        return $newarr;
    }

    function gaiSrc($str, $src)
    {
        $str = preg_replace("/src=([\"\'])?([^\s\"\']+)(?=\\1|\s|\"|\'>)/isx", "src=\\1" . trim($src), $str);
        return $str;
    }

    function deletePublic($textarea, $thisurl, $clhc, $thisbaseurl = "")
    {
        preg_match_all("/<img(?:(?<=Width)>|[^<>])*?window\.open\('(http[^<>]*\.(?:jpg|gif|png|jpeg))(?:(?<=Width)>|[^<>])*?" . ">/Uisx", $textarea, $nn);
        for ($i = 0; $i < count($nn[1]); $i++) {
            $textarea = str_replace($nn[0][$i], gaiSrc($nn[0][$i], $nn[1][$i]), $textarea);
        }

        if (is_string($textarea)) {
            $textarea = utf8encode($textarea);
            $textarea = strip_jscss($textarea); //####
            $textarea = preg_replace("/(<img[^<>]*)\s+?\/>/Uisx", "\\1>", $textarea);
            $textarea = preg_replace("/<span[^<>]*style=\\\?\"display\:none\\\?\"[^<>]*>.*<\/span>/Uisx", "", trim($textarea));
            $textarea = preg_replace("/<span[^<>]*>|<\/\s*span>/Uisx", "", $textarea);
            $textarea = preg_replace("/\(微博\)/m", "", trim($textarea));
            $textarea = preg_replace("/([0-9]+\-[0-9]+\-[0-9]+\s[0-9]+\:[0-9]+\:[0-9]+\s上传|下载附件).*$/m", "", $textarea);
            $textarea = preg_replace("/<(\/?)(b|strong)\s*\/?>/Uisx", "[\\1b]", $textarea);
            $textarea = preg_replace("/thumb_[0-9]+_[0-9]+_/Uisx", "", $textarea);
            $textarea = preg_replace("/^.*\/enpproperty\-\-\>/Uisx", "", trim($textarea));
            $textarea = preg_replace("/([0-9\-]+\s+[0-9\:]+|[0-9]天前)\s*(上传|修改|发表|更新)/Uisx", "", trim($textarea));
            $textarea = preg_replace("/<fieldset[^<>]*>(.*)<\/fieldset>/Uisx", "", trim($textarea));
            $textarea = str_replace('src="static/image/common/none.gif" ', '', $textarea);
            $textarea = str_replace('zoomfile', 'src', $textarea);
            $textarea = preg_replace("/<\/?br\s*\/?>|&lt;\/br\s*\/?&gt;/Uisx", "\r\n", $textarea);
            $textarea = htmltotxt($textarea, $clhc, $thisurl, $thisbaseurl);
            $textarea = preg_replace("/\[img\][^<>\[\]]*(\/images?\/smiley|images?\/common\/|\/images?\/smilies\/|\/miba\/images\/|images\/attachicons\/|\/common\/cf\/)[^<>\[\]]*\[\/img\]|\[b\]下载\[\/b\]|\([0-9\.a-z\s]+KB\)|[0-9]+天前[0-9\:]+?|附件\:\s*您所在的用户组无法下载或查看附件|<\/?blockquote[^<>]*>/Uisx", "", $textarea);
            $textarea = preg_replace("/\([\s0-9\.]+KB\,?\s*(下载次数\:\s*[\s0-9]+)?\)|下载次数\:[\s0-9]+?|(\s|　)[^\s]+\.jpg(\s|　)/Uisx", "\r\n", $textarea);
            $textarea = preg_replace("/本帖.*[0-9\-\s\:]编辑|<\/img>|<br\s*\/>|\&lt\;br\s*\/\&gt\;/Uisx", "", $textarea);
            $textarea = preg_replace("/本主题由[^\r\n]*/isx", "", $textarea);
            $textarea = preg_replace("/保存到相册|点击文件名|马上注册，.*？注册|\[img\][^<>\[\]]*qq_login.gif\[\/img\]/Uisx", "", $textarea);
            $textarea = preg_replace("/　　回复.*$/Uisx", "", $textarea);
            $textarea = preg_replace("/(\r(　|\s)*\n)+|[\r\n](　|\s)*[\r\n]+/", "\n", $textarea);
            $textarea = preg_replace("/[\r\n]+　　(\[hr\]\s*)+/", "[hr]", $textarea);
            $textarea = preg_replace("/(\[hr\](\s|　)*)+/", "[hr]", $textarea);
        } else if (is_array($textarea)) {
            foreach ($textarea as $k => $v) {
                $textarea[$k] = deletePublic($v, $thisurl, $clhc);
            }
        }
        return $textarea;
    }

    function jiebao($tempnr)
    {
        $tempnr = preg_replace("/<div[^<>]*>(?:\s*<div[^<>]*>)?(<\/?(a|span|p|br)[^<>]*>|\s|\&nbsp\;)*(<img[^<>]*>)(<" . "?\/?(a|span|p|br)[^<>]*>|([^\<\>a-z0-9_\s]|\&nbsp\;|\s))*<\/div>(\s*<\/div>)??/Uisx", "\\3\\4", $tempnr);
        return $tempnr;
    }

    function strlen_jifen($str)
    {
        $str = preg_replace("/<a\s?[^<>]*>.*<\/a>/Uisx", "", $str);
        $str = preg_replace("/<[^<>]*>/Uisx", "", $str);
        $str = preg_replace("/\s+/isx", " ", $str);
        return strlen($str);
    }

    function hasimg($str)
    {
        if (preg_match("/src=/", $str)) {
            return true;
        }
        return false;
    }

    function stripa($str)
    {
        $str = preg_replace("/<a\s?[^<>]*>.*<\/a>/Uisx", "", $str);
        return $str;
    }

    function curl38($url, $cookie = "", $Referer = "")
    {
        $timeout = 15;
        //$url = str_replace("%", "%25", trim(chop($url)));
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0");
        if ($Referer) curl_setopt($ch, CURLOPT_REFERER, $Referer);
        curl_setopt($ch, CURLOPT_HEADER, 1);
        if ($cookie) curl_setopt($ch, CURLOPT_COOKIE, $cookie);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
            'X-Requested-With: XMLHttpRequest',
            'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
            'Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3',
            'Accept-Encoding: gzip, deflate',
            'Connection: Keep-Alive',
        ));
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        ob_start();
        curl_exec($ch);
        curl_close($ch);
        $result = ob_get_contents();
        ob_end_clean();

        if (preg_match("/Location:\s*([^\r\n]+)/isx", $result, $nn)) {
            $url = trim($nn[1]);
            $result = curl38($url);
        } else {
            preg_match("/(^.*)(?:\r\n\r\n|\n\n)(.*?)$/Uis", $result, $nn);
            $result = $nn[2];
            if (@gzinflate(substr($result, 10))) {
                $result = @gzinflate(substr($result, 10));
            }
        }
        return $result;
    }

    function is_root($str)
    {
        $str = trim($str);
        $c = preg_count("\/", $str);
        if ($str == "" || $str == "\\" || $c < 3 && substr($str, 0, 7) == "http://" || $c == 3 && substr($str, -1, 1) == "/" && substr($str, 0, 7) == "http://") {
            return true;
        }
        return false;
    }

    function paiban($str)
    {
        $str = preg_replace("/　*?(([\(\)\[\]a-z]+?)|([\(\)\[\]0-9])+(?=\.|\:|、|\(\)))(\.|\:|、|\r|\n)?\s*　　/Uis", "　　\\1", $str);
        $str = preg_replace("/[\r\n]\s*(?!。|？|”|！|：)(?:\s|　)*([0-9]+)(?:\s|　)*/is", "\\1", $str);
        $str = preg_replace("/\s*　　(?=。|？|”|：|\[\/b\])|\[\/b\](?:\s|　)*\[b\]/is", "", $str);
        $str = preg_replace("/(\[\/b\]|\)|）|）|　)(?:\s|　)*((?:[0-9a-z]|\[b\]|一|二|三|四|五|六|七|八|九|十|http\:\/\/)+)/is", "\\1" . "\r\n\r\n" . "　　　\\2", $str);
        $str = preg_replace("/(?<!。|？|”|！)((\r?\n　*)+)*/is", "", $str);
        $str = preg_replace("/(?<=。|？|”|！)([0-9]+)/is", "\r\n　　\\1", $str);
        $str = preg_replace("/(\([0-9a-z]+\))(\s|　)*/is", "\r\n　　\\1", $str);
        $str = preg_replace("/(（[0-9a-z]+）)(\s|　)*/is", "\r\n　　\\1", $str);
        $str = preg_replace("/\[\/b\]　*/is", "[/b]\r\n　　", $str);
        $str = preg_replace("/(?:　|\s)*(、|\)|）|“|（|\(|\))(　|\s)*/is", "\\1", $str);
        $str = preg_replace("/(\(|（)(\s|　)*/is", "\\1", $str);
        $str = preg_replace("/(\[(?:\/img|\/flash|\/media)\])/is", "\\1\r\n", $str);
        $str = preg_replace("/(?<=\s|\W)([0-9]+\.)(?!\/|\.|[a-z])/is", "\r\n\\1", $str);
        return $str;
    }

    function is_re($re)
    {
//    if(preg_match("/(?<!\\\)\(([^\(\)](?!(?<!\\\)\))|\([^\(\)]*\)*)*$/Uisx",$re)){
//        return false;
//    }
        return true;
    }

    function ttbb($i)
    {
        global $rs, $thisurl, $thisbaseurl, $TTBB;
        $str = $TTBB[$i];
        $str = preg_replace("/<table[^<>]*>/Uisx", "[TABLE=50%,#E5EDF2]", $str);
        $str = preg_replace("/<\/table[^<>]*>/Uisx", "[/table]", $str);
        $str = preg_replace("/<tr[^<>]*>/Uisx", "[tr]", $str);
        $str = preg_replace("/<\/tr[^<>]*>/Uisx", "[/tr]", $str);
        $str = preg_replace("/<td[^<>]*>/Uisx", "[td]", $str);
        $str = preg_replace("/<\/td[^<>]*>/Uisx", "[/td]", $str);
        $str = preg_replace("/<(?!img)[^<>]*>/Uisx", "", $str);
        $str = preg_replace("/<(?:img)[^<>]*src=\"(.*)\"(?:[^<>]|(?<=width)>)*?" . ">/Uisxe", 'createimgubb("\\1", $title, $rs["loadimg"], $thisurl, $thisbaseurl)', $str);
        return $str;
    }

    function clzdname($str)
    {
        $str = preg_replace("/\s|\:|：|\r|\n|　|\-/", "", strip_tags($str));
        $str = preg_replace("/[\\\!a-z_\s\{\}\-\.\$]+?[\\\!\{\}\.\$][\\\!a-z_\s\{\}\.\$\-]+?/U", "", $str);
        $str = preg_replace("/\!|\?|\&[a-z]+\;/", "", $str);
        return trim($str);
    }

    function clzdvalue($str)
    {
        if (is_string($str)) {
            $str = preg_replace("/\:|：|\r|\n/", "", strip_tags(trim($str), "<IMG>"));
            $str = preg_replace("/\s+/", " ", $str);
        }
        return $str;
    }

    function array_merge3($oldarr, $arr, $aaname = "Array")
    {
        $a = 1;
        if (!name_exists($arr)) {
            for ($i = 0; $i < count($arr[1]); $i++) {
                $oldarr[0][] = $arr[0][$i];
                $oldarr[1][] = $arr[1][$i];
                $oldarr[2][] = $arr[2][$i];
            }
        } else {
            foreach ($arr as $k => $v) {
                if (is_int($k)) continue;
                if (is_array($v) && count($v) > 1) {
                    $oldarr[0][] = "";
                    $oldarr[1][] = trim($aaname);
                    $oldarr[2][] = delnamearr($arr);
                    break;
                } else {
                    $oldarr[0][] = "";
                    $oldarr[1][] = trim($k);
                    $oldarr[2][] = trim($v[0]);
                }
            }
        }
        return $oldarr;
    }

    function delarrayindex0($arr)
    {
        $newarr = array();
        $newarr[0] = $arr[1];
        $newarr[1] = $arr[2];
        return $newarr;
    }

    function name_exists($arr)
    {
        foreach ($arr as $k => $v) {
            if (preg_match("/^[^0-9]+$/", $k)) {
                if ($k != "name" && $k != "value") {
                    return true;
                    break;
                }
            }
        }
        return false;
    }

    function delnamearr($arr)
    {
        $newarr = array();
        foreach ($arr as $k => $v) {
            if (preg_match("/^[^0-9]+$/", $k)) {
                for ($i = 0; $i < count($arr[$k]); $i++) {
                    $newarr[$i][$k] = $v[$i];
                }
            }
        }
        return $newarr;
    }
}

if(!function_exists('bugmessage')){
    function bugmessage($mess){
        $GLOBALS['bugmessage'][]=$mess;
    }
}

?>
